void check_string_literal( FILE* fp, const char* s, char *buf, ... ) { char * b; va_list ap; va_start(ap,buf); printf(s); // expected-warning {{format string is not a string literal}} vprintf(s,ap); // // no-warning fprintf(fp,s); // expected-warning {{format string is not a string literal}} vfprintf(fp,s,ap); // no-warning asprintf(&b,s); // expected-warning {{format string is not a string lit}} vasprintf(&b,s,ap); // no-warning sprintf(buf,s); // expected-warning {{format string is not a string literal}} snprintf(buf,2,s); // expected-warning {{format string is not a string lit}} __builtin___sprintf_chk(buf,0,-1,s); // expected-warning {{format string is not a string literal}} __builtin___snprintf_chk(buf,2,0,-1,s); // expected-warning {{format string is not a string lit}} vsprintf(buf,s,ap); // no-warning vsnprintf(buf,2,s,ap); // no-warning vsnprintf(buf,2,global_fmt,ap); // expected-warning {{format string is not a string literal}} __builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // no-warning __builtin___vsnprintf_chk(buf,2,0,-1,global_fmt,ap); // expected-warning {{format string is not a string literal}} // rdar://6079877 printf("abc" "%*d", 1, 1); // no-warning printf("abc\ def" "%*d", 1, 1); // no-warning // <rdar://problem/6079850>, allow 'unsigned' (instead of 'int') to be used for both // the field width and precision. This deviates from C99, but is reasonably safe // and is also accepted by GCC. printf("%*d", (unsigned) 1, 1); // no-warning }
void check_string_literal( FILE* fp, const char* s, char *buf, ... ) { char * b; va_list ap; va_start(ap,buf); printf(s); // expected-warning {{format string is not a string literal}} vprintf(s,ap); // // no-warning fprintf(fp,s); // expected-warning {{format string is not a string literal}} vfprintf(fp,s,ap); // no-warning asprintf(&b,s); // expected-warning {{format string is not a string lit}} vasprintf(&b,s,ap); // no-warning sprintf(buf,s); // expected-warning {{format string is not a string literal}} snprintf(buf,2,s); // expected-warning {{format string is not a string lit}} __builtin___sprintf_chk(buf,0,-1,s); // expected-warning {{format string is not a string literal}} __builtin___snprintf_chk(buf,2,0,-1,s); // expected-warning {{format string is not a string lit}} vsprintf(buf,s,ap); // no-warning vsnprintf(buf,2,s,ap); // no-warning vsnprintf(buf,2,global_fmt,ap); // expected-warning {{format string is not a string literal}} __builtin___vsnprintf_chk(buf,2,0,-1,s,ap); // no-warning __builtin___vsnprintf_chk(buf,2,0,-1,global_fmt,ap); // expected-warning {{format string is not a string literal}} // rdar://6079877 printf("abc" "%*d", (unsigned) 1, 1); // expected-warning {{field width should have type 'int'}} printf("abc\ def" "%*d", (unsigned) 1, 1); // expected-warning {{field width should have type 'int'}} }
inline void * foo (void *x, char *y, int z) { struct S s; char b[256]; s.s = b; s.z = __builtin___sprintf_chk (s.s, 1, __builtin_object_size (s.s, 2), "Require"); if (s.z < 0) bar (u.t | c->t, "rls"); if (foo (x, s.s, s.z)) { } return (void *) 0; }