summaryrefslogtreecommitdiff
path: root/lib/vasnprintf.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2019-01-23 01:17:07 +0100
committerBruno Haible <bruno@clisp.org>2019-01-23 01:23:30 +0100
commit6c0f109fb98501fc8d65ea2c83501b45a80b00ab (patch)
treec275b20366ca12b18df8a1515294e3a96f4afeef /lib/vasnprintf.c
parent5447f440ef927283e63d5a1290dab292f7af1aea (diff)
downloadgnulib-6c0f109fb98501fc8d65ea2c83501b45a80b00ab.tar.gz
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.
Diffstat (limited to 'lib/vasnprintf.c')
-rw-r--r--lib/vasnprintf.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 465ecc3544..b14a95962b 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,