StringRef StrRef = FExpr->getString();
const char *Str = StrRef.data();
unsigned StrLen = StrRef.size();
+ const unsigned numDataArgs = TheCall->getNumArgs() - firstDataArg;
// CHECK: empty format string?
- if (StrLen == 0) {
+ if (StrLen == 0 && numDataArgs > 0) {
Diag(FExpr->getLocStart(), diag::warn_empty_format_string)
<< OrigFormatExpr->getSourceRange();
return;
if (isPrintf) {
CheckPrintfHandler H(*this, FExpr, OrigFormatExpr, firstDataArg,
- TheCall->getNumArgs() - firstDataArg,
- isa<ObjCStringLiteral>(OrigFormatExpr), Str,
- HasVAListArg, TheCall, format_idx);
+ numDataArgs, isa<ObjCStringLiteral>(OrigFormatExpr),
+ Str, HasVAListArg, TheCall, format_idx);
if (!analyze_format_string::ParsePrintfString(H, Str, Str + StrLen))
H.DoneProcessing();
}
else {
CheckScanfHandler H(*this, FExpr, OrigFormatExpr, firstDataArg,
- TheCall->getNumArgs() - firstDataArg,
- isa<ObjCStringLiteral>(OrigFormatExpr), Str,
- HasVAListArg, TheCall, format_idx);
+ numDataArgs, isa<ObjCStringLiteral>(OrigFormatExpr),
+ Str, HasVAListArg, TheCall, format_idx);
if (!analyze_format_string::ParseScanfString(H, Str, Str + StrLen))
H.DoneProcessing();
va_list ap;
va_start(ap,buf);
vprintf("",ap); // expected-warning {{format string is empty}}
- sprintf(buf,""); // expected-warning {{format string is empty}}
+ sprintf(buf, "", 1); // expected-warning {{format string is empty}}
+
+ // Don't warn about empty format strings when there are no data arguments.
+ // This can arise from macro expansions and non-standard format string
+ // functions.
+ sprintf(buf, ""); // no-warning
}
void check_wide_string(char* b, ...)