Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2014-11-06 14:08:14 +0300
committerCorinna Vinschen <corinna@vinschen.de>2014-11-06 14:08:14 +0300
commit97e2f27aa1c50d7ecb37314f912f7510d3ede879 (patch)
treef6b1fceb488c9f1e1714b447e216caaeddd0e2ec /newlib
parent3a4fcef804dac80dba686a793fdc8b96be6a54e6 (diff)
* 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.
Diffstat (limited to 'newlib')
-rw-r--r--newlib/ChangeLog6
-rw-r--r--newlib/libc/stdio/nano-vfprintf_i.c18
-rw-r--r--newlib/testsuite/newlib.stdio/nulprintf.c17
3 files changed, 32 insertions, 9 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 0382bbcd7..6fa883321 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,9 @@
+2014-11-06 Terry Guo <terry.guo@arm.com>
+
+ * 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.
+
2014-10-29 Jon Turney <jon.turney@dronecode.org.uk>
* libc/include/string.h: Correct guard for strcasecmp().
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. */
diff --git a/newlib/testsuite/newlib.stdio/nulprintf.c b/newlib/testsuite/newlib.stdio/nulprintf.c
new file mode 100644
index 000000000..5e4131bc4
--- /dev/null
+++ b/newlib/testsuite/newlib.stdio/nulprintf.c
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2014 by ARM Ltd. All rights reserved.
+ *
+ * Permission to use, copy, modify, and distribute this software
+ * is freely granted, provided that this notice is preserved.
+ */
+
+#include <stdio.h>
+#include "check.h"
+
+const char m[8] = {'M','M','M','M','M','M','M','M'};
+
+int main()
+{
+ printf ("%.*s\n", 8, m);
+ exit (0);
+}