]> Savannah Git Hosting - gnulib.git/commitdiff
vasnprintf: Don't use %n on Android.
authorBruno Haible <bruno@clisp.org>
Wed, 23 Jan 2019 00:17:07 +0000 (01:17 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 23 Jan 2019 00:23:30 +0000 (01:23 +0100)
Reported and fix suggested by Hugo Beauzée-Luyssen <hugo@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
lib/vasnprintf.c

index e3ec57bcec1b52a5deb1d82393732c055ade2115..f3972fd0825499cb30f068c76cf80624a90a57be 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2019-01-22  Bruno Haible  <bruno@clisp.org>
+
+       vasnprintf: Don't use %n on Android.
+       Reported and fix suggested by Hugo Beauzée-Luyssen <hugo@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  <bruno@clisp.org>
 
        *printf: Support cross-compilation to Android.
index 465ecc3544254ffb8a7c4cdfe5c1b646f0738a64..b14a95962b429ce9d73822b38ad803398bee3cc8 100644 (file)
@@ -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,