From 97e2f27aa1c50d7ecb37314f912f7510d3ede879 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 6 Nov 2014 11:08:14 +0000 Subject: * libc/stdio/nano-vfprintf_i.c (_printf_i): Use Newlib approach to handle string that might be not nul-terminated. * testsuite/newlib.stdio/nulprintf.c: New test. --- newlib/libc/stdio/nano-vfprintf_i.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'newlib/libc/stdio/nano-vfprintf_i.c') diff --git a/newlib/libc/stdio/nano-vfprintf_i.c b/newlib/libc/stdio/nano-vfprintf_i.c index b1b0d1d67..b75a142da 100644 --- a/newlib/libc/stdio/nano-vfprintf_i.c +++ b/newlib/libc/stdio/nano-vfprintf_i.c @@ -211,15 +211,15 @@ number: case 's': cp = GET_ARG (N, *ap, char_ptr_t); /* Precision gives the maximum number of chars to be written from a - string, and take prec == -1 into consideration. */ - if ((u_int)(pdata->size = strlen (cp)) > (u_int)(pdata->prec)) - pdata->size = pdata->prec; - /* Below code is kept for reading. The check is redundant because - pdata->prec will be set to pdata->size if it is -1 previously. */ -#if 0 - if (pdata->prec > pdata->size) -#endif - pdata->prec = pdata->size; + string, and take prec == -1 into consideration. + Use normal Newlib approach here to support case where cp is not + nul-terminated. */ + char *p = memchr (cp, 0, pdata->prec); + + if (p != NULL) + pdata->prec = p - cp; + + pdata->size = pdata->prec; goto non_number_nosign; default: /* "%?" prints ?, unless ? is NUL. */ -- cgit v1.2.3