1 /* See e.g. https://en.cppreference.com/w/c/io/fprintf
2 and https://www.man7.org/linux/man-pages/man3/sprintf.3.html */
5 sprintf(char* dst
, const char* fmt
, ...)
6 __attribute__((__nothrow__
));
8 #include "../../gcc.dg/analyzer/analyzer-decls.h"
11 test_passthrough (char* dst
, const char* fmt
)
13 /* This assumes that fmt doesn't have any arguments. */
14 return sprintf (dst
, fmt
);
21 int res
= sprintf (buf
, "foo");
22 /* TODO: ideally we would know the value of "res" is 3,
23 and known the content and strlen of "buf" after the call */
29 return sprintf (NULL
, "hello world"); /* { dg-warning "use of NULL where non-null expected" } */
33 test_null_fmt (char *dst
)
35 return sprintf (dst
, NULL
); /* { dg-warning "use of NULL where non-null expected" } */
39 test_uninit_dst (void)
42 return sprintf (dst
, "hello world"); /* { dg-warning "use of uninitialized value 'dst'" } */
46 test_uninit_fmt_ptr (char *dst
)
49 return sprintf (dst
, fmt
); /* { dg-warning "use of uninitialized value 'fmt'" } */
56 sprintf (buf
, "msg: %s\n", "abc");
57 __analyzer_eval (__builtin_strlen (buf
) == 8); /* { dg-warning "UNKNOWN" } */
58 // TODO: ideally would be TRUE