public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [Patch, Newlib]Remove unnecessary if comparison
@ 2014-10-29  8:35 Terry Guo
  2014-10-29 11:07 ` Corinna Vinschen
  0 siblings, 1 reply; 2+ messages in thread
From: Terry Guo @ 2014-10-29  8:35 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 1047 bytes --]

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);

[-- Attachment #2: remove-unnecessary-comparison-v1.txt --]
[-- Type: text/plain, Size: 667 bytes --]

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);

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Patch, Newlib]Remove unnecessary if comparison
  2014-10-29  8:35 [Patch, Newlib]Remove unnecessary if comparison Terry Guo
@ 2014-10-29 11:07 ` Corinna Vinschen
  0 siblings, 0 replies; 2+ messages in thread
From: Corinna Vinschen @ 2014-10-29 11:07 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 634 bytes --]

On Oct 29 16:35, Terry Guo wrote:
> 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  <...>
> 
>      * libc/stdio/vfprintf.c (_VFPRINTF_R): Remove unnecessary comparison.

Patch applied, except the NUL -> NULL part in the comment.  NUL refers
to the ASCII NUL character, NULL means a null pointer value.


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
Red Hat

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-10-29 11:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-29  8:35 [Patch, Newlib]Remove unnecessary if comparison Terry Guo
2014-10-29 11:07 ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).