Skip to content

Commit c8df209

Browse files
committed
Fix possible invalid output size in subsequent writes
The fixed buffer size was being used rather than the number of bytes read in the latest round of UTF-8 conversion.
1 parent 88f84a3 commit c8df209

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

paste/paste.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ void Write(const wchar_t *text, DWORD outputHandle = STD_OUTPUT_HANDLE, DWORD ch
101101
_utf8Buffer.Length = utf8ByteCount;
102102
}
103103
// "WideCharToMultiByte function operates most efficiently when both lpDefaultChar and lpUsedDefaultChar are set to NULL."
104-
int bytesConverted = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, text, chars, _utf8Buffer.Buffer, _utf8Buffer.Length, nullptr, nullptr);
105-
result = WriteFile(hOut, _utf8Buffer.Buffer, _utf8Buffer.Length, &charsWritten, nullptr);
104+
DWORD bytesConverted = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, text, chars, _utf8Buffer.Buffer, _utf8Buffer.Length, nullptr, nullptr);
105+
result = WriteFile(hOut, _utf8Buffer.Buffer, bytesConverted, &charsWritten, nullptr);
106106
if (charsWritten != utf8ByteCount)
107107
{
108108
ExitProcess(GetLastError());

0 commit comments

Comments
 (0)