Skip to content

Commit 4ac56a5

Browse files
committed
Fix FN for signed short passed as %hx into printf
1 parent c6bf881 commit 4ac56a5

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

lib/checkio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ void CheckIO::checkFormatString(const Token * const tok,
996996
if (specifier[1] == 'h') {
997997
if (!(argInfo.typeToken->str() == "char" && argInfo.typeToken->isUnsigned()))
998998
invalidPrintfArgTypeError_uint(tok, numFormat, specifier, &argInfo);
999-
} else if (argInfo.typeToken->str() != "short")
999+
} else if (!(argInfo.typeToken->str() == "short" && argInfo.typeToken->isUnsigned()))
10001000
invalidPrintfArgTypeError_uint(tok, numFormat, specifier, &argInfo);
10011001
break;
10021002
case 'l':

test/testio.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3255,6 +3255,7 @@ class TestIO : public TestFixture {
32553255
"}");
32563256
ASSERT_EQUALS("[test.cpp:2]: (warning) %hx in format string (no. 1) requires 'unsigned short' but the argument type is 'char'.\n"
32573257
"[test.cpp:2]: (warning) %hx in format string (no. 2) requires 'unsigned short' but the argument type is 'unsigned char'.\n"
3258+
"[test.cpp:2]: (warning) %hx in format string (no. 3) requires 'unsigned short' but the argument type is 'signed short'.\n"
32583259
"[test.cpp:2]: (warning) %hx in format string (no. 5) requires 'unsigned short' but the argument type is 'signed int'.\n"
32593260
"[test.cpp:2]: (warning) %hx in format string (no. 6) requires 'unsigned short' but the argument type is 'unsigned int'.\n"
32603261
"[test.cpp:2]: (warning) %hx in format string (no. 7) requires 'unsigned short' but the argument type is 'signed long'.\n"
@@ -3496,7 +3497,7 @@ class TestIO : public TestFixture {
34963497
TEST_PRINTF_WARN("%hx", "unsigned short", "char");
34973498
TEST_PRINTF_WARN("%hx", "unsigned short", "signed char");
34983499
TEST_PRINTF_WARN("%hx", "unsigned short", "unsigned char");
3499-
//TODO TEST_PRINTF_WARN("%hx", "unsigned short", "signed short");
3500+
TEST_PRINTF_WARN("%hx", "unsigned short", "signed short");
35003501
TEST_PRINTF_NOWARN("%hx", "unsigned short", "unsigned short");
35013502
TEST_PRINTF_WARN("%hx", "unsigned short", "signed int");
35023503
TEST_PRINTF_WARN("%hx", "unsigned short", "unsigned int");

0 commit comments

Comments
 (0)