summaryrefslogtreecommitdiff
path: root/tests/test_asprintf.c
diff options
context:
space:
mode:
authorjvoisin2024-05-20 14:48:35 +0200
committerJulien Voisin2024-05-26 20:19:27 +0000
commit1becad43298e74ba73bc66f9d44523e5d121c667 (patch)
tree009d0b1431d11ceb9d3ae1d33d1fd35638365ee9 /tests/test_asprintf.c
parent92c611ad8abb146ed548301de8bc011c2b17bccd (diff)
Add vasprintf/asprintf2.3
The only hardening being done here is to set the char** parameter to thos functions to NULL in case of an error, to prevent it from being used should people forget to check return values. This is already done on some BSD, as well as in Rocky Linux.
Diffstat (limited to 'tests/test_asprintf.c')
-rw-r--r--tests/test_asprintf.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/test_asprintf.c b/tests/test_asprintf.c
new file mode 100644
index 0000000..a02d110
--- /dev/null
+++ b/tests/test_asprintf.c
@@ -0,0 +1,20 @@
1#define _GNU_SOURCE
2#include "common.h"
3
4#include <assert.h>
5#include <stdio.h>
6#include <stdlib.h>
7
8int main(int argc, char** argv) {
9 char* buf;
10 asprintf(&buf, "total: %d+%d=%d", 1, 2, 3);
11 puts(buf);
12 free(buf);
13
14#ifndef __clang__
15 asprintf(&buf, "total: %", 1);
16 assert(buf == NULL);
17#endif
18
19 return 0;
20}