]> Savannah Git Hosting - gnulib.git/commitdiff
*vasnprintf: Add a stricter runtime check.
authorBruno Haible <bruno@clisp.org>
Tue, 4 Feb 2025 10:46:34 +0000 (11:46 +0100)
committerBruno Haible <bruno@clisp.org>
Tue, 4 Feb 2025 10:46:34 +0000 (11:46 +0100)
* lib/printf-args.c (PRINTF_FETCHARGS): Abort in case of an unknown
type.

ChangeLog
lib/printf-args.c

index a5fdf782e1cdafe0cc166e117c2af97ae445c472..5b853546353433f2c27ca985198165f397c97d84 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-02-04  Bruno Haible  <bruno@clisp.org>
+
+       *vasnprintf: Add a stricter runtime check.
+       * lib/printf-args.c (PRINTF_FETCHARGS): Abort in case of an unknown
+       type.
+
 2025-02-03  Bruno Haible  <bruno@clisp.org>
 
        bootstrap: Remove undesired output.
@@ -7,7 +13,7 @@
 
 2025-02-03  Paul Eggert  <eggert@cs.ucla.edu>
 
-       c-vasnprintf: pacify -Wswitch-enum
+       *vasnprintf: pacify -Wswitch-enum
        * lib/printf-args.c (PRINTF_FETCHARGS):
        Mention TYPE_NONE as being a default case.
        * lib/vasnprintf.c (VASNPRINTF): Use switch (+E).
index e0bf87c7eee95bd269f7fe3e0ed2f4ec220776b1..b83ec1e8a81e99579b7da1d8789bc1c56963477c 100644 (file)
@@ -32,6 +32,9 @@
 /* Get INT_WIDTH.  */
 #include <limits.h>
 
+/* Get abort().  */
+#include <stdlib.h>
+
 #ifdef STATIC
 STATIC
 #endif
@@ -297,9 +300,18 @@ PRINTF_FETCHARGS (va_list args, arguments *a)
         break;
 #endif
       case TYPE_NONE:
-      default:
-        /* Unknown type.  */
+        /* Argument i is not used by any directive, but some argument with
+           number > i is used by a format directive.  POSIX says that this
+           is invalid:
+             "When numbered argument specifications are used, specifying the
+              Nth argument requires that all the leading arguments, from the
+              first to the (N-1)th, are specified in the format string."
+           The reason is that we cannot know how many bytes to skip in the
+           va_arg sequence.  */
         return -1;
+      default:
+        /* Unknown type.  Should not happen.  */
+        abort ();
       }
   return 0;
 }