From 46897fefd6aef4168f35c1f366c833d715c3bdaa Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Wed, 28 Apr 2021 18:12:36 -0500 Subject: Clean up more 32-bit assumptions. --- src/wcautil/wcascript.cpp | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) (limited to 'src/wcautil/wcascript.cpp') diff --git a/src/wcautil/wcascript.cpp b/src/wcautil/wcascript.cpp index b6629850..a7e98491 100644 --- a/src/wcautil/wcascript.cpp +++ b/src/wcautil/wcascript.cpp @@ -247,9 +247,8 @@ extern "C" HRESULT WIXAPI WcaCaScriptWriteString( { HRESULT hr = S_OK; DWORD cbFile = 0; - DWORD cbWrite = 0; - DWORD cbTotalWritten = 0; WCHAR delim[] = { MAGIC_MULTISZ_DELIM }; // magic char followed by NULL terminator + SIZE_T cch = 0; cbFile = ::SetFilePointer(hScript->hScriptFile, 0, NULL, FILE_END); if (INVALID_SET_FILE_POINTER == cbFile) @@ -261,32 +260,15 @@ extern "C" HRESULT WIXAPI WcaCaScriptWriteString( // before adding our new data on the end of the file. if (0 < cbFile) { - cbWrite = sizeof(delim); - cbTotalWritten = 0; - while (cbTotalWritten < cbWrite) - { - DWORD cbWritten = 0; - if (!::WriteFile(hScript->hScriptFile, reinterpret_cast(delim) + cbTotalWritten, cbWrite - cbTotalWritten, &cbWritten, NULL)) - { - ExitWithLastError(hr, "Failed to write data to ca script."); - } - - cbTotalWritten += cbWritten; - } + hr = FileWriteHandle(hScript->hScriptFile, reinterpret_cast(delim), sizeof(delim)); + ExitOnFailure(hr, "Failed to write data to ca script."); } - cbWrite = lstrlenW(wzValue) * sizeof(WCHAR); - cbTotalWritten = 0; - while (cbTotalWritten < cbWrite) - { - DWORD cbWritten = 0; - if (!::WriteFile(hScript->hScriptFile, reinterpret_cast(wzValue) + cbTotalWritten, cbWrite - cbTotalWritten, &cbWritten, NULL)) - { - ExitWithLastError(hr, "Failed to write data to ca script."); - } + hr = ::StringCchLengthW(wzValue, STRSAFE_MAX_CCH, reinterpret_cast(&cch)); + ExitOnRootFailure(hr, "Failed to get length of ca script string."); - cbTotalWritten += cbWritten; - } + hr = FileWriteHandle(hScript->hScriptFile, reinterpret_cast(wzValue), static_cast(cch) * sizeof(WCHAR)); + ExitOnFailure(hr, "Failed to write data to ca script."); LExit: return hr; -- cgit v1.2.3-55-g6feb