Hi Tim and Hugo, > > I also don't see much here (Debian unstable): > > > > $ grep -A1 -i 'checking.*printf' config.log > > configure:6305: checking for vasnprintf > > configure:6305: result: no > > configure:6305: checking for snprintf > > configure:6305: result: yes > > -- > > configure:8450: checking whether snprintf returns a byte count as in C99 > > configure:8548: result: yes > > configure:8559: checking for snprintf > > configure:8559: result: yes > > -- > > configure:8568: checking whether _snprintf is declared > > configure:8568: result: no > > > > What does that grep look for you ? > > $ grep -A1 'checking .*printf' config.log > configure:6326: checking for vasnprintf > configure:6326: gcc -o conftest -g -O2 conftest.c >&5 > -- > configure:6326: checking for snprintf > configure:6326: gcc -o conftest -g -O2 conftest.c >&5 > -- > configure:8471: checking whether snprintf returns a byte count as in C99 > configure:8558: gcc -o conftest -g -O2 conftest.c >&5 > -- > configure:8580: checking for snprintf > configure:8580: result: yes > -- > configure:8589: checking whether _snprintf is declared > configure:8589: gcc -c -g -O2 conftest.c >&5
I did these steps: 1) Create a testdir ./gnulib-tool --create-testdir --dir=../testdir-printf-posix --single-configure \ dprintf-posix fprintf-posix printf-posix snprintf-posix \ sprintf-posix vasnprintf-posix vasprintf-posix vdprintf-posix \ vfprintf-posix vprintf-posix vsnprintf-posix vsprintf-posix 2) Tarred the resulting directory 3) Transfered it to the device (Android 4.3 with 'Terminal IDE' app in my case), 4) Unpacked it there, 5) configured it, 6) Copy&pasted the configure output. The configure output contains the lines checking whether printf supports size specifiers as in C99... yes checking whether printf supports 'long double' arguments... yes checking whether printf supports infinite 'double' arguments... no checking whether printf supports infinite 'long double' arguments... no checking whether printf supports the 'a' and 'A' directives... no checking whether printf supports the 'F' directive... no checking whether printf supports the 'n' directive... no checking whether printf supports the 'ls' directive... no checking whether printf supports POSIX/XSI format strings with positions... yes checking whether printf supports the grouping flag... no checking whether printf supports the left-adjust flag correctly... yes checking whether printf supports the zero flag correctly... no checking whether printf supports large precisions... yes checking whether printf survives out-of-memory conditions... no checking for snprintf... yes checking whether snprintf truncates the result as in C99... yes checking whether snprintf returns a byte count as in C99... yes checking whether snprintf fully supports the 'n' directive... no checking whether snprintf respects a size of 1... yes checking whether vsnprintf respects a zero size as in C99... yes With this, I am in the position to update the results in printf.m4, and even add cross-compilation guesses. Since snprintf is behaving well enough, we can disable the use of %n, like you suggested. Done through the attached patches. Bruno
>From 5447f440ef927283e63d5a1290dab292f7af1aea Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Tue, 22 Jan 2019 22:44:49 +0100 Subject: [PATCH 1/2] *printf: Support cross-compilation to Android. * m4/printf.m4: Add cross-compilation guesses for Android. --- ChangeLog | 5 ++ m4/printf.m4 | 190 ++++++++++++++++++++++++++++++++++++----------------------- 2 files changed, 120 insertions(+), 75 deletions(-) diff --git a/ChangeLog b/ChangeLog index c496144..e3ec57b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2019-01-22 Bruno Haible <br...@clisp.org> + + *printf: Support cross-compilation to Android. + * m4/printf.m4: Add cross-compilation guesses for Android. + 2019-01-21 Bruno Haible <br...@clisp.org> diacrit: Mark deprecated. diff --git a/m4/printf.m4 b/m4/printf.m4 index 1db13bf..cbf6ae4 100644 --- a/m4/printf.m4 +++ b/m4/printf.m4 @@ -1,4 +1,4 @@ -# printf.m4 serial 59 +# printf.m4 serial 60 dnl Copyright (C) 2003, 2007-2019 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -79,6 +79,8 @@ changequote(,)dnl netbsd[1-2]* | netbsdelf[1-2]* | netbsdaout[1-2]* | netbsdcoff[1-2]*) gl_cv_func_printf_sizes_c99="guessing no";; netbsd*) gl_cv_func_printf_sizes_c99="guessing yes";; + # Guess yes on Android. + linux*-android*) gl_cv_func_printf_sizes_c99="guessing yes";; changequote([,])dnl # Guess yes on MSVC, no on mingw. mingw*) AC_EGREP_CPP([Known], [ @@ -132,17 +134,20 @@ int main () [gl_cv_func_printf_long_double=yes], [gl_cv_func_printf_long_double=no], [case "$host_os" in - beos*) gl_cv_func_printf_long_double="guessing no";; - # Guess yes on MSVC, no on mingw. - mingw*) AC_EGREP_CPP([Known], [ + # Guess no on BeOS. + beos*) gl_cv_func_printf_long_double="guessing no";; + # Guess yes on Android. + linux*-android*) gl_cv_func_printf_long_double="guessing yes";; + # Guess yes on MSVC, no on mingw. + mingw*) AC_EGREP_CPP([Known], [ #ifdef _MSC_VER Known #endif - ], - [gl_cv_func_printf_long_double="guessing yes"], - [gl_cv_func_printf_long_double="guessing no"]) - ;; - *) gl_cv_func_printf_long_double="guessing yes";; + ], + [gl_cv_func_printf_long_double="guessing yes"], + [gl_cv_func_printf_long_double="guessing no"]) + ;; + *) gl_cv_func_printf_long_double="guessing yes";; esac ]) ]) @@ -250,6 +255,8 @@ changequote(,)dnl netbsd*) gl_cv_func_printf_infinite="guessing yes";; # Guess yes on BeOS. beos*) gl_cv_func_printf_infinite="guessing yes";; + # Guess no on Android. + linux*-android*) gl_cv_func_printf_infinite="guessing no";; changequote([,])dnl # Guess yes on MSVC, no on mingw. mingw*) AC_EGREP_CPP([Known], [ @@ -456,6 +463,8 @@ changequote(,)dnl # Guess yes on HP-UX >= 11. hpux[7-9]* | hpux10*) gl_cv_func_printf_infinite_long_double="guessing no";; hpux*) gl_cv_func_printf_infinite_long_double="guessing yes";; + # Guess no on Android. + linux*-android*) gl_cv_func_printf_infinite_long_double="guessing no";; changequote([,])dnl # Guess yes on MSVC, no on mingw. mingw*) AC_EGREP_CPP([Known], [ @@ -566,6 +575,8 @@ int main () [gl_cv_func_printf_directive_a="guessing yes"], [gl_cv_func_printf_directive_a="guessing no"]) ;; + # Guess no on Android. + linux*-android*) gl_cv_func_printf_directive_a="guessing no";; # Guess no on native Windows. mingw*) gl_cv_func_printf_directive_a="guessing no";; # If we don't know, assume the worst. @@ -623,6 +634,8 @@ changequote(,)dnl # Guess yes on Solaris >= 2.10. solaris2.[1-9][0-9]*) gl_cv_func_printf_directive_f="guessing yes";; solaris*) gl_cv_func_printf_directive_f="guessing no";; + # Guess no on Android. + linux*-android*) gl_cv_func_printf_directive_f="guessing no";; changequote([,])dnl # Guess yes on MSVC, no on mingw. mingw*) AC_EGREP_CPP([Known], [ @@ -688,9 +701,11 @@ int main () [gl_cv_func_printf_directive_n=yes], [gl_cv_func_printf_directive_n=no], [case "$host_os" in - # Guess no on native Windows. - mingw*) gl_cv_func_printf_directive_n="guessing no";; - *) gl_cv_func_printf_directive_n="guessing yes";; + # Guess no on Android. + linux*-android*) gl_cv_func_printf_directive_n="guessing no";; + # Guess no on native Windows. + mingw*) gl_cv_func_printf_directive_n="guessing no";; + *) gl_cv_func_printf_directive_n="guessing yes";; esac ]) ]) @@ -766,14 +781,16 @@ int main () [ changequote(,)dnl case "$host_os" in - openbsd*) gl_cv_func_printf_directive_ls="guessing no";; - irix*) gl_cv_func_printf_directive_ls="guessing no";; - solaris*) gl_cv_func_printf_directive_ls="guessing no";; - cygwin*) gl_cv_func_printf_directive_ls="guessing no";; - beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";; - # Guess yes on native Windows. - mingw*) gl_cv_func_printf_directive_ls="guessing yes";; - *) gl_cv_func_printf_directive_ls="guessing yes";; + openbsd*) gl_cv_func_printf_directive_ls="guessing no";; + irix*) gl_cv_func_printf_directive_ls="guessing no";; + solaris*) gl_cv_func_printf_directive_ls="guessing no";; + cygwin*) gl_cv_func_printf_directive_ls="guessing no";; + beos* | haiku*) gl_cv_func_printf_directive_ls="guessing no";; + # Guess no on Android. + linux*-android*) gl_cv_func_printf_directive_ls="guessing no";; + # Guess yes on native Windows. + mingw*) gl_cv_func_printf_directive_ls="guessing yes";; + *) gl_cv_func_printf_directive_ls="guessing yes";; esac changequote([,])dnl ]) @@ -810,11 +827,13 @@ int main () changequote(,)dnl case "$host_os" in netbsd[1-3]* | netbsdelf[1-3]* | netbsdaout[1-3]* | netbsdcoff[1-3]*) - gl_cv_func_printf_positions="guessing no";; - beos*) gl_cv_func_printf_positions="guessing no";; - # Guess no on native Windows. - mingw* | pw*) gl_cv_func_printf_positions="guessing no";; - *) gl_cv_func_printf_positions="guessing yes";; + gl_cv_func_printf_positions="guessing no";; + beos*) gl_cv_func_printf_positions="guessing no";; + # Guess yes on Android. + linux*-android*) gl_cv_func_printf_positions="guessing yes";; + # Guess no on native Windows. + mingw* | pw*) gl_cv_func_printf_positions="guessing no";; + *) gl_cv_func_printf_positions="guessing yes";; esac changequote([,])dnl ]) @@ -849,11 +868,13 @@ int main () [ changequote(,)dnl case "$host_os" in - cygwin*) gl_cv_func_printf_flag_grouping="guessing no";; - netbsd*) gl_cv_func_printf_flag_grouping="guessing no";; - # Guess no on native Windows. - mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";; - *) gl_cv_func_printf_flag_grouping="guessing yes";; + cygwin*) gl_cv_func_printf_flag_grouping="guessing no";; + netbsd*) gl_cv_func_printf_flag_grouping="guessing no";; + # Guess no on Android. + linux*-android*) gl_cv_func_printf_flag_grouping="guessing no";; + # Guess no on native Windows. + mingw* | pw*) gl_cv_func_printf_flag_grouping="guessing no";; + *) gl_cv_func_printf_flag_grouping="guessing yes";; esac changequote([,])dnl ]) @@ -890,14 +911,16 @@ int main () [ changequote(,)dnl case "$host_os" in - # Guess yes on HP-UX 11. - hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";; - # Guess no on HP-UX 10 and older. - hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";; - # Guess yes on native Windows. - mingw*) gl_cv_func_printf_flag_leftadjust="guessing yes";; - # Guess yes otherwise. - *) gl_cv_func_printf_flag_leftadjust="guessing yes";; + # Guess yes on HP-UX 11. + hpux11*) gl_cv_func_printf_flag_leftadjust="guessing yes";; + # Guess no on HP-UX 10 and older. + hpux*) gl_cv_func_printf_flag_leftadjust="guessing no";; + # Guess yes on Android. + linux*-android*) gl_cv_func_printf_flag_leftadjust="guessing yes";; + # Guess yes on native Windows. + mingw*) gl_cv_func_printf_flag_leftadjust="guessing yes";; + # Guess yes otherwise. + *) gl_cv_func_printf_flag_leftadjust="guessing yes";; esac changequote([,])dnl ]) @@ -935,14 +958,16 @@ int main () [ changequote(,)dnl case "$host_os" in - # Guess yes on glibc systems. - *-gnu* | gnu*) gl_cv_func_printf_flag_zero="guessing yes";; - # Guess yes on BeOS. - beos*) gl_cv_func_printf_flag_zero="guessing yes";; - # Guess no on native Windows. - mingw*) gl_cv_func_printf_flag_zero="guessing no";; - # If we don't know, assume the worst. - *) gl_cv_func_printf_flag_zero="guessing no";; + # Guess yes on glibc systems. + *-gnu* | gnu*) gl_cv_func_printf_flag_zero="guessing yes";; + # Guess yes on BeOS. + beos*) gl_cv_func_printf_flag_zero="guessing yes";; + # Guess no on Android. + linux*-android*) gl_cv_func_printf_flag_zero="guessing no";; + # Guess no on native Windows. + mingw*) gl_cv_func_printf_flag_zero="guessing no";; + # If we don't know, assume the worst. + *) gl_cv_func_printf_flag_zero="guessing no";; esac changequote([,])dnl ]) @@ -995,10 +1020,12 @@ int main () changequote(,)dnl case "$host_os" in # Guess no only on Solaris, native Windows, and BeOS systems. - solaris*) gl_cv_func_printf_precision="guessing no" ;; - mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;; - beos*) gl_cv_func_printf_precision="guessing no" ;; - *) gl_cv_func_printf_precision="guessing yes" ;; + solaris*) gl_cv_func_printf_precision="guessing no" ;; + mingw* | pw*) gl_cv_func_printf_precision="guessing no" ;; + beos*) gl_cv_func_printf_precision="guessing no" ;; + # Guess yes on Android. + linux*-android*) gl_cv_func_printf_precision="guessing yes" ;; + *) gl_cv_func_printf_precision="guessing yes" ;; esac changequote([,])dnl ]) @@ -1095,28 +1122,30 @@ changequote([,])dnl if test "$gl_cv_func_printf_enomem" = "guessing no"; then changequote(,)dnl case "$host_os" in - # Guess yes on glibc systems. - *-gnu* | gnu*) gl_cv_func_printf_enomem="guessing yes";; - # Guess yes on Solaris. - solaris*) gl_cv_func_printf_enomem="guessing yes";; - # Guess yes on AIX. - aix*) gl_cv_func_printf_enomem="guessing yes";; - # Guess yes on HP-UX/hppa. - hpux*) case "$host_cpu" in - hppa*) gl_cv_func_printf_enomem="guessing yes";; - *) gl_cv_func_printf_enomem="guessing no";; - esac - ;; - # Guess yes on IRIX. - irix*) gl_cv_func_printf_enomem="guessing yes";; - # Guess yes on OSF/1. - osf*) gl_cv_func_printf_enomem="guessing yes";; - # Guess yes on BeOS. - beos*) gl_cv_func_printf_enomem="guessing yes";; - # Guess yes on Haiku. - haiku*) gl_cv_func_printf_enomem="guessing yes";; - # If we don't know, assume the worst. - *) gl_cv_func_printf_enomem="guessing no";; + # Guess yes on glibc systems. + *-gnu* | gnu*) gl_cv_func_printf_enomem="guessing yes";; + # Guess yes on Solaris. + solaris*) gl_cv_func_printf_enomem="guessing yes";; + # Guess yes on AIX. + aix*) gl_cv_func_printf_enomem="guessing yes";; + # Guess yes on HP-UX/hppa. + hpux*) case "$host_cpu" in + hppa*) gl_cv_func_printf_enomem="guessing yes";; + *) gl_cv_func_printf_enomem="guessing no";; + esac + ;; + # Guess yes on IRIX. + irix*) gl_cv_func_printf_enomem="guessing yes";; + # Guess yes on OSF/1. + osf*) gl_cv_func_printf_enomem="guessing yes";; + # Guess yes on BeOS. + beos*) gl_cv_func_printf_enomem="guessing yes";; + # Guess yes on Haiku. + haiku*) gl_cv_func_printf_enomem="guessing yes";; + # Guess no on Android. + linux*-android*) gl_cv_func_printf_enomem="guessing no";; + # If we don't know, assume the worst. + *) gl_cv_func_printf_enomem="guessing no";; esac changequote([,])dnl fi @@ -1208,6 +1237,8 @@ changequote(,)dnl netbsd*) gl_cv_func_snprintf_truncation_c99="guessing yes";; # Guess yes on BeOS. beos*) gl_cv_func_snprintf_truncation_c99="guessing yes";; + # Guess yes on Android. + linux*-android*) gl_cv_func_snprintf_truncation_c99="guessing yes";; # Guess no on native Windows. mingw*) gl_cv_func_snprintf_truncation_c99="guessing no";; # If we don't know, assume the worst. @@ -1299,6 +1330,8 @@ changequote(,)dnl netbsd*) gl_cv_func_snprintf_retval_c99="guessing yes";; # Guess yes on BeOS. beos*) gl_cv_func_snprintf_retval_c99="guessing yes";; + # Guess yes on Android. + linux*-android*) gl_cv_func_snprintf_retval_c99="guessing yes";; changequote([,])dnl # Guess yes on MSVC, no on mingw. mingw*) AC_EGREP_CPP([Known], [ @@ -1391,6 +1424,8 @@ changequote(,)dnl netbsd*) gl_cv_func_snprintf_directive_n="guessing yes";; # Guess yes on BeOS. beos*) gl_cv_func_snprintf_directive_n="guessing yes";; + # Guess no on Android. + linux*-android*) gl_cv_func_snprintf_directive_n="guessing no";; # Guess no on native Windows. mingw*) gl_cv_func_snprintf_directive_n="guessing no";; # If we don't know, assume the worst. @@ -1440,9 +1475,11 @@ int main() [gl_cv_func_snprintf_size1=yes], [gl_cv_func_snprintf_size1=no], [case "$host_os" in - # Guess yes on native Windows. - mingw*) gl_cv_func_snprintf_size1="guessing yes" ;; - *) gl_cv_func_snprintf_size1="guessing yes" ;; + # Guess yes on Android. + linux*-android*) gl_cv_func_snprintf_size1="guessing yes" ;; + # Guess yes on native Windows. + mingw*) gl_cv_func_snprintf_size1="guessing yes" ;; + *) gl_cv_func_snprintf_size1="guessing yes" ;; esac ]) ]) @@ -1540,6 +1577,8 @@ changequote(,)dnl netbsd*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; # Guess yes on BeOS. beos*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; + # Guess yes on Android. + linux*-android*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; # Guess yes on native Windows. mingw* | pw*) gl_cv_func_vsnprintf_zerosize_c99="guessing yes";; # If we don't know, assume the worst. @@ -1626,6 +1665,7 @@ dnl NetBSD 4.0 . ? ? ? ? ? . ? . ? ? ? ? ? . dnl NetBSD 3.0 . . . . # # . ? # # ? # . # . . . . . . dnl Haiku . . . # # # . # . . . . . ? . . ? . . . dnl BeOS # # . # # # . ? # . ? . # ? . . ? . . . +dnl Android 4.3 . . # # # # # # . # . # . # . . . # . . dnl old mingw / msvcrt # # # # # # . . # # . # # ? . # # # . . dnl MSVC 9 # # # # # # # . # # . # # ? # # # # . . dnl mingw 2009-2011 . # . # . . . . # # . . . ? . . . . . . -- 2.7.4
From 6c0f109fb98501fc8d65ea2c83501b45a80b00ab Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Wed, 23 Jan 2019 01:17:07 +0100 Subject: [PATCH 2/2] vasnprintf: Don't use %n on Android. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported and fix suggested by Hugo Beauzée-Luyssen <h...@beauzee.fr> in <https://lists.gnu.org/archive/html/bug-gnulib/2018-12/msg00123.html>. * lib/vasnprintf.c (VASNPRINTF): Don’t use %n on Android. --- ChangeLog | 7 +++++++ lib/vasnprintf.c | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index e3ec57b..f3972fd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2019-01-22 Bruno Haible <br...@clisp.org> + vasnprintf: Don't use %n on Android. + Reported and fix suggested by Hugo Beauzée-Luyssen <h...@beauzee.fr> in + <https://lists.gnu.org/archive/html/bug-gnulib/2018-12/msg00123.html>. + * lib/vasnprintf.c (VASNPRINTF): Don’t use %n on Android. + +2019-01-22 Bruno Haible <br...@clisp.org> + *printf: Support cross-compilation to Android. * m4/printf.m4: Add cross-compilation guesses for Android. diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c index 465ecc3..b14a959 100644 --- a/lib/vasnprintf.c +++ b/lib/vasnprintf.c @@ -4874,6 +4874,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, # if ! (((__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)) \ && !defined __UCLIBC__) \ || (defined __APPLE__ && defined __MACH__) \ + || defined __ANDROID__ \ || (defined _WIN32 && ! defined __CYGWIN__)) fbp[1] = '%'; fbp[2] = 'n'; @@ -4895,6 +4896,14 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp, On Mac OS X 10.13 or newer, the use of %n in format strings in writable memory by default crashes the program, so we should avoid it in this situation. */ + /* On Android, we know that snprintf's return value conforms to + ISO C 99: the tests gl_SNPRINTF_RETVAL_C99 and + gl_SNPRINTF_TRUNCATION_C99 pass. + Therefore we can avoid using %n in this situation. + Starting on 2018-03-07, the use of %n in format strings + produces a fatal error (see + <https://android.googlesource.com/platform/bionic/+/41398d03b7e8e0dfb951660ae713e682e9fc0336>), + so we should avoid it. */ /* On native Windows systems (such as mingw), we can avoid using %n because: - Although the gl_SNPRINTF_TRUNCATION_C99 test fails, -- 2.7.4