[Patch, Newlib]Remove unnecessary if comparison

Terry Guo terry.guo@arm.com
Wed Oct 29 08:35:00 GMT 2014


Hi there,

As shown in attached patch, the (p!=NULL) means we found target character
within width 'prec'. So the 'size' is always smaller than the width 'prec',
thus the inner if statement is unnecessary. Is it ok?

BR,
Terry

newlib/ChangeLog
2014-10-29  Terry Guo  <terry.guo@arm.com>

     * libc/stdio/vfprintf.c (_VFPRINTF_R): Remove unnecessary comparison.


diff --git a/newlib/libc/stdio/vfprintf.c b/newlib/libc/stdio/vfprintf.c
index dd9c22a..fbca32e 100644
--- a/newlib/libc/stdio/vfprintf.c
+++ b/newlib/libc/stdio/vfprintf.c
@@ -1516,16 +1516,14 @@ string:
 			if (prec >= 0) {
 				/*
 				 * can't use strlen; can only look for the
-				 * NUL in the first `prec' characters, and
+				 * NULL in the first `prec' characters, and
 				 * strlen () will go further.
 				 */
 				char *p = memchr (cp, 0, prec);
 
-				if (p != NULL) {
+				if (p != NULL)
 					size = p - cp;
-					if (size > prec)
-						size = prec;
-				} else
+				else
 					size = prec;
 			} else
 				size = strlen (cp);
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: remove-unnecessary-comparison-v1.txt
URL: <http://sourceware.org/pipermail/newlib/attachments/20141029/5c08637f/attachment.txt>


More information about the Newlib mailing list