regex memory corruption regression test
[libc-test] / src / regression / printf-fmt-n.c
1 // commit: 5cbd76c6b05b381f269e0e204e10690d69f1d6ea 2011-02-16
2 // commit: bdc9ed15651b70e89f83c5a9f7d1ba349e624503 2011-02-20
3 // printf %n fmt
4 #include <stdint.h>
5 #include <stdio.h>
6 #include "test.h"
7
8 #define T(n,nfmt,fmt) do { \
9         if ((ret = sprintf(buf, "%256d%d" nfmt "%d", 1, 2, &n, 3)) != 258) \
10                 t_error("expexted sprintf to write 258 chars, got %d\n", ret); \
11         if (n != 257) \
12                 t_error("%%n format failed: wanted 257, got " fmt "\n", n); \
13 } while(0)
14
15 int main(void)
16 {
17         char buf[1024];
18         int ret;
19         int i;
20         long l;
21         long long ll;
22         short h;
23         size_t z;
24         uintmax_t j;
25
26         T(i,    "%n",   "%d");
27         T(l,   "%ln",  "%ld");
28         T(ll, "%lln", "%lld");
29         T(h,   "%hn",   "%d");
30         T(z,   "%zn",  "%zd");
31         T(j,   "%jn",  "%jd");
32
33         return t_status;
34 }