summaryrefslogtreecommitdiff
path: root/tests/test_vasprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_vasprintf.c')
-rw-r--r--tests/test_vasprintf.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/test_vasprintf.c b/tests/test_vasprintf.c
new file mode 100644
index 0000000..2f71714
--- /dev/null
+++ b/tests/test_vasprintf.c
@@ -0,0 +1,36 @@
1#define _GNU_SOURCE
2#include "common.h"
3
4#include <assert.h>
5#include <stdarg.h>
6#include <stdio.h>
7#include <stdlib.h>
8
9void test(const char *fmt, ...)
10{
11 char* buf;
12 va_list args;
13 va_start(args, fmt);
14 vasprintf(&buf, fmt, args);
15 va_end(args);
16 puts(buf);
17 free(buf);
18}
19
20void test2(const char *fmt, ...)
21{
22 char* buf;
23 va_list args;
24 va_start(args, fmt);
25 vasprintf(&buf, fmt, args);
26 va_end(args);
27 assert(buf == NULL);
28}
29
30int main(int argc, char** argv) {
31 test("Total: %d+%d=%d", 1, 2, 3);
32#ifndef __clang__
33 test2("Total: %", 1, 2, 3);
34#endif
35 return 0;
36}