diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2021-05-17 09:37:01 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2021-05-17 09:37:01 +0000 |
commit | 13ddb157c08b5f7ea7b88d470b37236e640ccee9 (patch) | |
tree | f2b09e3df9af0849716306d83668d9523f2001a3 | |
parent | 27f7e397929973378246ee02f1bf3a7d2d9765dd (diff) | |
download | mpfr-13ddb157c08b5f7ea7b88d470b37236e640ccee9.tar.gz |
[src/vasprintf.c] Fixed buffer_cat: replaced incorrect assertion len > 0
by a test.
Note that len == 0 is possible when outputting an integer 0 (either a
native one or mpfr_prec_t) with precision field = 0. The consequence
of this bug:
* In debug mode (MPFR_ASSERTD assertion checking), one would get an
assertion failure.
* Otherwise, there should be no side effects since the code was valid
for len == 0, possibly except with LTO (very unlikely, though).
This incorrect assertion was added on 2009-03-13 in r6099.
git-svn-id: https://scm.gforge.inria.fr/anonscm/svn/mpfr/trunk@14521 280ebfd0-de03-0410-8827-d642c229c3f4
-rw-r--r-- | src/vasprintf.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/vasprintf.c b/src/vasprintf.c index de3b49fae..ff50a931c 100644 --- a/src/vasprintf.c +++ b/src/vasprintf.c @@ -645,7 +645,13 @@ buffer_widen (struct string_buffer *b, size_t len) static int buffer_cat (struct string_buffer *b, const char *s, size_t len) { - MPFR_ASSERTD (len > 0); + /* If len == 0, which is possible when outputting an integer 0 + (either a native one or mpfr_prec_t) with precision field = 0, + do nothing. This test is not necessary since the code below is + valid for len == 0, but this is safer, just in case. */ + if (len == 0) + return 0; + MPFR_ASSERTD (len <= strlen (s)); if (buffer_incr_len (b, len)) |