aboutsummaryrefslogtreecommitdiffstats
path: root/test/regression/varargs3.c
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 /test/regression/varargs3.c
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.
Diffstat (limited to 'test/regression/varargs3.c')
-rw-r--r--test/regression/varargs3.c52
1 files changed, 52 insertions, 0 deletions
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;
+}