comparison lib/vasnprintf.c @ 9361:40389da21b02

Don't use %n on glibc >= 2.3 systems.
author Bruno Haible <bruno@clisp.org>
date Fri, 19 Oct 2007 01:50:42 +0200
parents 46dab2096f98
children 8b3c48038257
comparison
equal deleted inserted replaced
9360:7b62d3737179 9361:40389da21b02
3383 *fbp = 'f'; 3383 *fbp = 'f';
3384 else 3384 else
3385 #endif 3385 #endif
3386 *fbp = dp->conversion; 3386 *fbp = dp->conversion;
3387 #if USE_SNPRINTF 3387 #if USE_SNPRINTF
3388 # if !(__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3))
3388 fbp[1] = '%'; 3389 fbp[1] = '%';
3389 fbp[2] = 'n'; 3390 fbp[2] = 'n';
3390 fbp[3] = '\0'; 3391 fbp[3] = '\0';
3392 # else
3393 /* On glibc2 systems from glibc >= 2.3 - probably also older
3394 ones - we know that snprintf's returns value conforms to
3395 ISO C 99: the gl_SNPRINTF_DIRECTIVE_N test passes.
3396 Therefore we can avoid using %n in this situation.
3397 On glibc2 systems from 2004-10-18 or newer, the use of %n
3398 in format strings in writable memory may crash the program
3399 (if compiled with _FORTIFY_SOURCE=2), so we should avoid it
3400 in this situation. */
3401 fbp[1] = '\0';
3402 # endif
3391 #else 3403 #else
3392 fbp[1] = '\0'; 3404 fbp[1] = '\0';
3393 #endif 3405 #endif
3394 3406
3395 /* Construct the arguments for calling snprintf or sprintf. */ 3407 /* Construct the arguments for calling snprintf or sprintf. */