Fix incorrect warning with `%zi` in format string (#3437)

This commit is contained in:
FabianWolff 2021-09-05 07:34:22 +02:00 committed by GitHub
parent ccb31d8510
commit cd5fa015c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -1782,7 +1782,7 @@ void CheckIO::invalidScanfArgTypeError_int(const Token* tok, nonneg int numForma
else else
errmsg << "intmax_t"; errmsg << "intmax_t";
} else if (specifier[0] == 'z') { } else if (specifier[0] == 'z') {
if (specifier[1] == 'd') if (specifier[1] == 'd' || specifier[1] == 'i')
errmsg << "ssize_t"; errmsg << "ssize_t";
else else
errmsg << "size_t"; errmsg << "size_t";
@ -1875,7 +1875,7 @@ static void printfFormatType(std::ostream& os, const std::string& specifier, boo
else else
os << "intmax_t"; os << "intmax_t";
} else if (specifier[0] == 'z') { } else if (specifier[0] == 'z') {
if (specifier[1] == 'd') if (specifier[1] == 'd' || specifier[1] == 'i')
os << "ssize_t"; os << "ssize_t";
else else
os << "size_t"; os << "size_t";

View File

@ -1533,6 +1533,8 @@ private:
TEST_SCANF_NOWARN("%zd", "ssize_t", "ssize_t"); TEST_SCANF_NOWARN("%zd", "ssize_t", "ssize_t");
TEST_SCANF_WARN_AKA("%zd", "ssize_t", "ptrdiff_t", "signed long", "signed long long"); TEST_SCANF_WARN_AKA("%zd", "ssize_t", "ptrdiff_t", "signed long", "signed long long");
TEST_SCANF_WARN_AKA("%zi", "ssize_t", "size_t", "unsigned long", "unsigned long long");
TEST_SCANF_WARN("%tu", "unsigned ptrdiff_t", "bool"); TEST_SCANF_WARN("%tu", "unsigned ptrdiff_t", "bool");
TEST_SCANF_WARN("%tu", "unsigned ptrdiff_t", "char"); TEST_SCANF_WARN("%tu", "unsigned ptrdiff_t", "char");
TEST_SCANF_WARN("%tu", "unsigned ptrdiff_t", "signed char"); TEST_SCANF_WARN("%tu", "unsigned ptrdiff_t", "signed char");
@ -3705,6 +3707,9 @@ private:
TEST_PRINTF_WARN_AKA("%jx", "uintmax_t", "std::intptr_t", "signed long", "signed long long"); TEST_PRINTF_WARN_AKA("%jx", "uintmax_t", "std::intptr_t", "signed long", "signed long long");
TEST_PRINTF_WARN_AKA("%jx", "uintmax_t", "std::uintptr_t", "unsigned long", "unsigned long long"); TEST_PRINTF_WARN_AKA("%jx", "uintmax_t", "std::uintptr_t", "unsigned long", "unsigned long long");
TEST_PRINTF_WARN_AKA("%zd", "ssize_t", "size_t", "unsigned long", "unsigned long long");
TEST_PRINTF_WARN_AKA("%zi", "ssize_t", "size_t", "unsigned long", "unsigned long long");
TEST_PRINTF_WARN("%zu", "size_t", "bool"); TEST_PRINTF_WARN("%zu", "size_t", "bool");
TEST_PRINTF_WARN("%zu", "size_t", "char"); TEST_PRINTF_WARN("%zu", "size_t", "char");
TEST_PRINTF_WARN("%zu", "size_t", "signed char"); TEST_PRINTF_WARN("%zu", "size_t", "signed char");