|
|
commit 4951fd1801e94915e462c0fa96765f8ee2187b16
Author: Greg Ercolano <erco@seriss.com>
AuthorDate: Tue Mar 23 18:27:30 2021 -0700
Commit: Greg Ercolano <erco@seriss.com>
CommitDate: Tue Mar 23 18:27:30 2021 -0700
Better fix for issue #206.
Albrecht caught a problem with my strncat use (see comments for 12d8da9c).
I noticed we have fl_strlcpy() and fl_strlcat() which is what was really
needed here.
src/Fl_Native_File_Chooser_WIN32.cxx | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git src/Fl_Native_File_Chooser_WIN32.cxx src/Fl_Native_File_Chooser_WIN32.cxx
index 717f8c0..9a60f4c 100644
--- src/Fl_Native_File_Chooser_WIN32.cxx
+++ src/Fl_Native_File_Chooser_WIN32.cxx
@@ -30,6 +30,7 @@
#define FNFC_MAX_PATH 32768 // XXX: MAX_PATH under win32 is 260, too small for modern use
#include <FL/fl_string.h> // fl_strdup()
+#include "flstring.h" // fl_strlcpy()/cat()
#include <FL/Fl_Native_File_Chooser.H>
# include <windows.h>
# include <commdlg.h> // OPENFILENAMEW, GetOpenFileName()
@@ -522,16 +523,11 @@ int Fl_WinAPI_Native_File_Chooser_Driver::showfile() {
// eg. "/dir/name\0foo1\0foo2\0foo3\0\0"
//
char pathname[FNFC_MAX_PATH];
- for ( const WCHAR *s = dirname + dirlen + 1;
- *s; s += (wcslen(s)+1)) {
- // 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);
+ for ( const WCHAR *s = dirname + dirlen + 1; *s; s += (wcslen(s)+1)) {
+ // ISSUE #206: replace strncpy/cat with fl_strlcpy/cat
+ fl_strlcpy(pathname, wchartoutf8(dirname), FNFC_MAX_PATH);
+ fl_strlcat(pathname, "\\", FNFC_MAX_PATH);
+ fl_strlcat(pathname, wchartoutf8(s), FNFC_MAX_PATH);
add_pathname(pathname);
}
}
[ Direct Link to Message ] | |
|
| |