diff mbox

[committed] Fix quadmath_snprintf behavior on string truncation

Message ID 20110228203412.GM30899@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Feb. 28, 2011, 8:34 p.m. UTC
Hi!

snprintf of course needs to zero terminate the provided string always unless
size is 0, but quadmath_snprintf was errorneously not terminating it if
we hit the user supplied size.

Fixed thusly, committed to trunk after bootstrap/regtest on x86_64-linux and
i686-linux.

2011-02-28  Jakub Jelinek  <jakub@redhat.com>

	* printf/quadmath-printf.c (quadmath_snprintf): Make sure
	that for size > 0 str is always zero terminated.


	Jakub
diff mbox

Patch

--- libquadmath/printf/quadmath-printf.c.jj	2011-02-16 11:13:15.000000000 +0100
+++ libquadmath/printf/quadmath-printf.c	2011-02-28 18:30:07.590808338 +0100
@@ -256,7 +256,7 @@  quadmath_snprintf (char *str, size_t siz
 
   qfp.fp = NULL;
   qfp.str = str;
-  qfp.size = size;
+  qfp.size = size ? size - 1 : 0;
   qfp.len = 0;
   qfp.file_p = 0;
 
@@ -265,7 +265,7 @@  quadmath_snprintf (char *str, size_t siz
   else
     __quadmath_printf_fp (&qfp, &info, (const void *const *)&fpnum_addr2);
 
-  if (qfp.size)
+  if (size)
     *qfp.str = '\0';
 
   return qfp.len;