fortify-headers

standalone fortify-source implementation
git clone git://git.2f30.org/fortify-headers
Log | Files | Refs | README | LICENSE

test_vasprintf.c (612B)


      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 
      9 void 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 
     20 void 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 
     30 int 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 }