public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] stdio-common/printf-prs.c: Simplify test
@ 2021-03-24 18:07 Alejandro Colomar
  2021-03-29 19:32 ` Adhemerval Zanella
  0 siblings, 1 reply; 4+ messages in thread
From: Alejandro Colomar @ 2021-03-24 18:07 UTC (permalink / raw)
  To: libc-alpha; +Cc: Alejandro Colomar

The test was being repeated for all the remaining code in the for loop.
Test once, and 'continue' to next iteration if necessary, so that the
following code can assume that the necessary condition is met.

Minor changes: fix some mixed tabs & spaces to use spaces only.

Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
---
 stdio-common/printf-prs.c | 44 ++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 21 deletions(-)

diff --git a/stdio-common/printf-prs.c b/stdio-common/printf-prs.c
index 1d4e00553d..a0c5c5487b 100644
--- a/stdio-common/printf-prs.c
+++ b/stdio-common/printf-prs.c
@@ -72,30 +72,32 @@ parse_printf_format (const char *fmt, size_t n, int *argtypes)
       /* Parse this spec.  */
       nargs += __parse_one_specmb (f, nargs, &spec, &max_ref_arg);
 
+      if ((size_t) spec.width_arg >= n)
+        continue;
+
       /* If the width is determined by an argument this is an int.  */
-      if (spec.width_arg != -1 && (size_t) spec.width_arg < n)
-	argtypes[spec.width_arg] = PA_INT;
+      if (spec.width_arg != -1)
+        argtypes[spec.width_arg] = PA_INT;
 
       /* If the precision is determined by an argument this is an int.  */
-      if (spec.prec_arg != -1 && (size_t) spec.prec_arg < n)
-	argtypes[spec.prec_arg] = PA_INT;
-
-      if ((size_t) spec.data_arg < n)
-	switch (spec.ndata_args)
-	  {
-	  case 0:		/* No arguments.  */
-	    break;
-	  case 1:		/* One argument; we already have the type.  */
-	    argtypes[spec.data_arg] = spec.data_arg_type;
-	    break;
-	  default:
-	    /* We have more than one argument for this format spec.  We must
-               call the arginfo function again to determine all the types.  */
-	    (void) (*__printf_arginfo_table[spec.info.spec])
-	      (&spec.info, n - spec.data_arg, &argtypes[spec.data_arg],
-	       &spec.size);
-	    break;
-	  }
+      if (spec.prec_arg != -1)
+        argtypes[spec.prec_arg] = PA_INT;
+
+      switch (spec.ndata_args)
+        {
+        case 0:		/* No arguments.  */
+          break;
+        case 1:		/* One argument; we already have the type.  */
+          argtypes[spec.data_arg] = spec.data_arg_type;
+          break;
+        default:
+          /* We have more than one argument for this format spec.  We must
+             call the arginfo function again to determine all the types.  */
+          (void) (*__printf_arginfo_table[spec.info.spec])
+            (&spec.info, n - spec.data_arg, &argtypes[spec.data_arg],
+             &spec.size);
+          break;
+        }
     }
 
   return MAX (nargs, max_ref_arg);
-- 
2.31.0


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

end of thread, other threads:[~2021-03-29 20:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 18:07 [PATCH] stdio-common/printf-prs.c: Simplify test Alejandro Colomar
2021-03-29 19:32 ` Adhemerval Zanella
2021-03-29 20:35   ` Alejandro Colomar (man-pages)
2021-03-29 20:43     ` Adhemerval Zanella

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