Mercurial > hg > octave-lojdl > gnulib-hg
diff lib/vasnprintf.c @ 9676:cbba7bfe013b
Don't use %n on native Woe32 systems, to avoid a crash on Windows Vista systems.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 08 Feb 2008 02:32:48 +0100 |
parents | b69f1141e94f |
children | 32d08ee66484 |
line wrap: on
line diff
--- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -4010,7 +4010,7 @@ #endif *fbp = dp->conversion; #if USE_SNPRINTF -# if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) +# if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3) || ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__)) fbp[1] = '%'; fbp[2] = 'n'; fbp[3] = '\0'; @@ -4023,6 +4023,21 @@ in format strings in writable memory may crash the program (if compiled with _FORTIFY_SOURCE=2), so we should avoid it in this situation. */ + /* On native Win32 systems (such as mingw), we can avoid using + %n because: + - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, + snprintf does not write more than the specified number + of bytes. (snprintf (buf, 3, "%d %d", 4567, 89) writes + '4', '5', '6' into buf, not '4', '5', '\0'.) + - Although the gl_SNPRINTF_RETVAL_C99 test fails, snprintf + allows us to recognize the case of an insufficient + buffer size: it returns -1 in this case. + On native Win32 systems (such as mingw) where the OS is + Windows Vista, the use of %n in format strings by default + crashes the program. See + <http://gcc.gnu.org/ml/gcc/2007-06/msg00122.html> and + <http://msdn2.microsoft.com/en-us/library/ms175782(VS.80).aspx> + So we should avoid %n in this situation. */ fbp[1] = '\0'; # endif #else