add an sscanf regression test
authorSzabolcs Nagy <nsz@port70.net>
Thu, 14 Mar 2019 23:05:04 +0000 (23:05 +0000)
committerSzabolcs Nagy <nsz@port70.net>
Sat, 16 Mar 2019 12:24:29 +0000 (12:24 +0000)
src/regression/sscanf-eof.c [new file with mode: 0644]

diff --git a/src/regression/sscanf-eof.c b/src/regression/sscanf-eof.c
new file mode 100644 (file)
index 0000000..f67a378
--- /dev/null
@@ -0,0 +1,18 @@
+// introduced by d6c855caa88ddb1ab6e24e23a14b1e7baf4ba9c7 2018-09-15
+// sscanf may crash on short input
+#include <stdio.h>
+#include "test.h"
+
+int main(void)
+{
+       const char *s = "0";
+       const char *fmt = "%f%c";
+       float f = 1.0f;
+       char c = 'x';
+       int r = sscanf(s, fmt, &f, &c);
+       if (r != 1)
+               t_error("sscanf(\"%s\", \"%s\",..) returned %d, wanted 1\n", s, fmt, r);
+       if (f != 0.0f || c != 'x')
+               t_error("sscanf(\"%s\", \"%s\",..) assigned f=%f c='%c', wanted i=0 c='x'\n", s, fmt, f, c);
+       return t_status;
+}