diff options
| author | Greg Ercolano <erco@seriss.com> | 2021-03-23 12:24:04 -0700 |
|---|---|---|
| committer | Greg Ercolano <erco@seriss.com> | 2021-03-23 12:24:04 -0700 |
| commit | 12d8da9cb64aa6b8574a4b595df5009eb264b2d7 (patch) | |
| tree | b6a3bbc85188decdeda90ff4322d126ea2f4b5ea /src | |
| parent | 8a9e25cdac38f72cf9d561b8e4db0831b5ba7817 (diff) | |
Solve issue #206 warning.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Fl_Native_File_Chooser_WIN32.cxx | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/Fl_Native_File_Chooser_WIN32.cxx b/src/Fl_Native_File_Chooser_WIN32.cxx index 860d677d9..717f8c013 100644 --- a/src/Fl_Native_File_Chooser_WIN32.cxx +++ b/src/Fl_Native_File_Chooser_WIN32.cxx @@ -524,10 +524,14 @@ int Fl_WinAPI_Native_File_Chooser_Driver::showfile() { char pathname[FNFC_MAX_PATH]; for ( const WCHAR *s = dirname + dirlen + 1; *s; s += (wcslen(s)+1)) { - strncpy(pathname, wchartoutf8(dirname), FNFC_MAX_PATH); - strncat(pathname, "\\", FNFC_MAX_PATH); - strncat(pathname, wchartoutf8(s), FNFC_MAX_PATH); - pathname[FNFC_MAX_PATH-1] = 0; + // ISSUE #206 -- beware strncpy() vs. strncat(): + // > strncpy() doesn't guarantee null termination but strncat() does. + // > strncat() can write to n+1, whereas strncpy() only writes to n. + // fl_snprintf() can't be used here b/c wchartoutf8() returns a static str. + // + strncpy(pathname, wchartoutf8(dirname), FNFC_MAX_PATH); pathname[FNFC_MAX_PATH-1] = 0; + strncat(pathname, "\\", FNFC_MAX_PATH-1); + strncat(pathname, wchartoutf8(s), FNFC_MAX_PATH-1); add_pathname(pathname); } } |
