aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXavier Leroy <xavier.leroy@college-de-france.fr>2019-02-02 16:05:12 +0100
committerXavier Leroy <xavierleroy@users.noreply.github.com>2019-02-04 16:18:43 +0100
commit5382c3cc9b24f59a050b4ef862cab392fa33ed30 (patch)
tree4431f7e43a22825920155a3783f581311770d353
parent455c56fac3f0e29777aa2fde2b62b5beffea0260 (diff)
downloadcompcert-5382c3cc9b24f59a050b4ef862cab392fa33ed30.tar.gz
compcert-5382c3cc9b24f59a050b4ef862cab392fa33ed30.zip
Test for NULL in variable argument lists
Sometimes a vararg function receives a NULL-terminated list of pointers. This can fail if sizeof(NULL) < sizeof(void *), as this test illustrates.
-rw-r--r--test/regression/Makefile2
-rw-r--r--test/regression/varargs3.c52
2 files changed, 53 insertions, 1 deletions
diff --git a/test/regression/Makefile b/test/regression/Makefile
index 191a2285..5d40e2c9 100644
--- a/test/regression/Makefile
+++ b/test/regression/Makefile
@@ -23,7 +23,7 @@ TESTS=int32 int64 floats floats-basics \
TESTS_COMP=attribs1 bitfields1 bitfields2 bitfields3 bitfields4 \
bitfields5 bitfields6 bitfields7 bitfields8 \
builtins-$(ARCH) packedstruct1 packedstruct2 alignas \
- varargs1 varargs2 sections alias
+ varargs1 varargs2 varargs3 sections alias
# Can run, both in compiled mode and in interpreter mode,
# but produce processor-dependent results, so no reference output in Results
diff --git a/test/regression/varargs3.c b/test/regression/varargs3.c
new file mode 100644
index 00000000..a46d81e3
--- /dev/null
+++ b/test/regression/varargs3.c
@@ -0,0 +1,52 @@
+#include <stdarg.h>
+#include <stdio.h>
+
+void initialize(int first, ...)
+{
+ va_list ap;
+ va_start(ap, first);
+ while (1) {
+ int * p = va_arg(ap, int *);
+ if (p == NULL) break;
+ *p = first;
+ first++;
+ }
+}
+
+void test(void)
+{
+ int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
+ initialize(42, &a, &b, &c, &d, &e, &f, &g, &h, &i, &j,
+ &k, &l, &m, &n, &o, &p, &q, NULL);
+ printf("a = %d\n", a);
+ printf("b = %d\n", b);
+ printf("c = %d\n", c);
+ printf("d = %d\n", d);
+ printf("e = %d\n", e);
+ printf("f = %d\n", f);
+ printf("g = %d\n", g);
+ printf("h = %d\n", h);
+ printf("i = %d\n", i);
+ printf("j = %d\n", j);
+ printf("k = %d\n", k);
+ printf("l = %d\n", l);
+ printf("m = %d\n", m);
+ printf("n = %d\n", n);
+ printf("o = %d\n", o);
+ printf("p = %d\n", p);
+ printf("q = %d\n", q);
+}
+
+void wipestack(void)
+{
+ unsigned int b[100];
+ int i;
+ for (i = 0; i < 100; i++) ((volatile unsigned int *)b)[i] = 0xDEADBEEFU;
+}
+
+int main()
+{
+ wipestack();
+ test();
+ return 0;
+}