summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2024-01-31 21:00:44 -0500
committerJakob Kaivo <jkk@ung.org>2024-01-31 21:00:44 -0500
commit1e85d81f5b4773275471fe7bbc707e8d64fb0a08 (patch)
tree8fe64f82d9bd333d885f07c8cbc3006c2d8a8472
parentd242a498377350add06ba70da2f7ce1d2c593cc1 (diff)
trigger UB on unknown conversion specifier and invalid #/0 flags
-rw-r--r--src/stdio/__printf.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/stdio/__printf.c b/src/stdio/__printf.c
index 72eb1585..db34e288 100644
--- a/src/stdio/__printf.c
+++ b/src/stdio/__printf.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
+#include <string.h>
#include <wchar.h>
#ifdef _POSIX_SOURCE
@@ -203,6 +204,12 @@ int (__printf)(struct io_options *opt, const char * format, va_list arg)
flags |= UPPER;
}
+ if ((flags & ALT) && (!strchr("xXaAeEfFgG", format[i]))) {
+ __undefined("In call to %s(): The # flag is undefined for %%%c", opt->fnname, format[i]);
+ } else if ((flags & ZERO) && (!strchr("diouxXaAeEfFgG", format[i]))) {
+ __undefined("In call to %s(): The 0 flag is undefined for %%%c", opt->fnname, format[i]);
+ }
+
switch (format[i]) {
case 'o': /* unsigned int */
case 'u':
@@ -324,7 +331,7 @@ int (__printf)(struct io_options *opt, const char * format, va_list arg)
break;
default: /* undefined */
- return -nout;
+ __undefined("In call to %s(): Unknown conversion specifier %%%c", opt->fnname, format[i]);
}
}