diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-11-25 21:17:27 +0100 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2023-11-25 21:17:27 +0100 |
| commit | 09242ee16d4b1d2573027829644e6add9e4c25f0 (patch) | |
| tree | 61368b79c6299f7be7134414c20c0bb16a18b51d /src | |
| parent | 4a461efae6fa36aeb50e61e381dc2ecf95b83d23 (diff) | |
Fix and improve fl_call_main.c
- add missing NULL pointer at end of argv
- fix #if condition for compilation
Todo: another update will follow soon, using a standardized FLTK
interface for argument conversion to UTF-8 for non-MSVC builds.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fl_call_main.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/fl_call_main.c b/src/fl_call_main.c index 5cb7335b2..025e7f03c 100644 --- a/src/fl_call_main.c +++ b/src/fl_call_main.c @@ -41,7 +41,7 @@ * The _MSC_VER macro is tested to compile it only for Visual Studio * platforms because GNU platforms (MinGW, MSYS) don't need it. */ -#if defined(_MSC_VER) && !defined(FL_DLL) +#if !defined(FL_DLL) && !defined (__GNUC__) #include <FL/fl_utf8.h> #include <FL/fl_string_functions.h> @@ -57,8 +57,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int rc; int i; - int argc; - char** argv; + int argc = 0; + char** argv = NULL; char strbuf[2048]; /* @@ -80,7 +80,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, /* Convert the command line arguments to UTF-8 */ LPWSTR *wideArgv = CommandLineToArgvW(GetCommandLineW(), &argc); - argv = malloc(argc * sizeof(void *)); + argv = (char **)malloc((argc + 1) * sizeof(char *)); for (i = 0; i < argc; i++) { int ret = WideCharToMultiByte(CP_UTF8, /* CodePage */ 0, /* dwFlags */ @@ -92,6 +92,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, NULL); /* lpUsedDefaultChar */ argv[i] = fl_strdup(strbuf); } + argv[argc] = NULL; // required by C standard at end of list /* Free the wide character string array */ LocalFree(wideArgv); @@ -119,4 +120,4 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, #else /* STR# 2973: solves "empty translation unit" error */ typedef int dummy; -#endif /* defined(_MSC_VER) && !defined(FL_DLL) */ +#endif /* !defined(FL_DLL) && !defined (__GNUC__) */ |
