#840: Fixes fixed buffer size in Fl::args_to_utf8() (fl_call_main)
This commit is contained in:
parent
a118930d95
commit
fdf578d936
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user