Hi Adrian, > rpl_fprintf is wrongly being used on Ubuntu 18.04 due to: > > $ cat test.c > /* gl_PRINTF_DIRECTIVE_N */ > #include <stdio.h> > #include <stdlib.h> > #include <string.h> > static char fmtstring[10]; > static char buf[100]; > int main () > { > int count = -1; > /* Copy the format string. Some systems (glibc with _FORTIFY_SOURCE=2) > support %n in format strings in read-only memory but not in writable > memory. */ > strcpy (fmtstring, "%d %n"); > if (sprintf (buf, fmtstring, 123, &count, 33, 44, 55) < 0 > || strcmp (buf, "123 ") != 0 > || count != 4) > return 1; > return 0; > } > $ gcc -O2 test.c -o test && ./test > *** %n in writable segment detected *** > Aborted > $
gnulib works as designed. gnulib is designed to override system function so as to make them POSIX compliant. POSIX [1] specifies that support for %n in the *printf functions is mandatory. As you have shown with the test program, glibc does not provide %n support when the CFLAGS contain _FORTIFY_SOURCE=2; gnulib rectifies that. Bruno [1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html