diff options
| author | MatthiasWM <visualc.git@matthiasm.com> | 2023-12-15 12:56:06 +0100 |
|---|---|---|
| committer | MatthiasWM <visualc.git@matthiasm.com> | 2023-12-15 12:56:06 +0100 |
| commit | fdf578d936abacafe2bfb8d08255a5093b1f1ea3 (patch) | |
| tree | f9cc1e148553514cec1c0819303b4e46dd1edf41 /src | |
| parent | a118930d954d9ca20e9ea0b7ce5155f084578228 (diff) | |
#840: Fixes fixed buffer size in Fl::args_to_utf8() (fl_call_main)
Diffstat (limited to 'src')
| -rw-r--r-- | src/fl_call_main.c | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/fl_call_main.c b/src/fl_call_main.c index de05b98d4..88049eec7 100644 --- a/src/fl_call_main.c +++ b/src/fl_call_main.c @@ -70,7 +70,6 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, int i; int argc = 0; char** argv = NULL; - char strbuf[2048]; /* * If we are compiling in debug mode, open a console window so @@ -97,15 +96,34 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, /* Convert the command line arguments to UTF-8 */ for (i = 0; i < argc; i++) { - int ret = WideCharToMultiByte(CP_UTF8, /* CodePage */ - 0, /* dwFlags */ - wideArgv[i], /* lpWideCharStr */ - -1, /* cchWideChar */ - strbuf, /* lpMultiByteStr */ - sizeof(strbuf), /* cbMultiByte */ - NULL, /* lpDefaultChar */ - NULL); /* lpUsedDefaultChar */ - argv[i] = _strdup(strbuf); + // find the required size of the buffer + int u8size = WideCharToMultiByte(CP_UTF8, // CodePage + 0, // dwFlags + wideArgv[i], // lpWideCharStr + -1, // cchWideChar + NULL, // lpMultiByteStr + 0, // cbMultiByte + NULL, // lpDefaultChar + NULL); // lpUsedDefaultChar + if (u8size > 0) { + char *strbuf = (char *)malloc(u8size); + int ret = WideCharToMultiByte(CP_UTF8, // CodePage + 0, // dwFlags + wideArgv[i], // lpWideCharStr + -1, // cchWideChar + strbuf, // lpMultiByteStr + u8size, // cbMultiByte + NULL, // lpDefaultChar + NULL); // lpUsedDefaultChar + if (ret) { + argv[i] = strbuf; + } else { + argv[i] = _strdup(""); + free(strbuf); + } + } else { + argv[i] = _strdup(""); + } } argv[argc] = NULL; // required by C standard at end of list |
