mirror of
https://github.com/fltk/fltk.git
synced 2026-05-27 02:46:34 +08:00
#840: Fixes fixed buffer size in Fl::args_to_utf8()
This commit is contained in:
@@ -302,24 +302,40 @@ int Fl_WinAPI_System_Driver::rename(const char *fnam, const char *newnam) {
|
|||||||
// See Fl::args_to_utf8()
|
// See Fl::args_to_utf8()
|
||||||
int Fl_WinAPI_System_Driver::args_to_utf8(int argc, char ** &argv) {
|
int Fl_WinAPI_System_Driver::args_to_utf8(int argc, char ** &argv) {
|
||||||
int i;
|
int i;
|
||||||
char strbuf[2048]; // FIXME: allocate argv and strings dynamically
|
|
||||||
|
|
||||||
// Convert the command line arguments to UTF-8
|
// Convert the command line arguments to UTF-8
|
||||||
LPWSTR *wideArgv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
LPWSTR *wideArgv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
||||||
argv = (char **)malloc((argc + 1) * sizeof(char *));
|
argv = (char **)malloc((argc + 1) * sizeof(char *));
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
int ret = WideCharToMultiByte(CP_UTF8, // CodePage
|
// find the required size of the buffer
|
||||||
|
int u8size = WideCharToMultiByte(CP_UTF8, // CodePage
|
||||||
0, // dwFlags
|
0, // dwFlags
|
||||||
wideArgv[i], // lpWideCharStr
|
wideArgv[i], // lpWideCharStr
|
||||||
-1, // cchWideChar
|
-1, // cchWideChar
|
||||||
strbuf, // lpMultiByteStr
|
NULL, // lpMultiByteStr
|
||||||
sizeof(strbuf), // cbMultiByte
|
0, // cbMultiByte
|
||||||
NULL, // lpDefaultChar
|
NULL, // lpDefaultChar
|
||||||
NULL); // lpUsedDefaultChar
|
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)
|
if (ret) {
|
||||||
strbuf[0] = '\0'; // return empty string
|
argv[i] = strbuf;
|
||||||
argv[i] = fl_strdup(strbuf);
|
} else {
|
||||||
|
argv[i] = _strdup("");
|
||||||
|
::free(strbuf);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
argv[i] = _strdup("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
argv[argc] = NULL; // required NULL pointer at end of list
|
argv[argc] = NULL; // required NULL pointer at end of list
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user