Skip to content

Commit 11ac737

Browse files
Fix #14302 FP invalidScanfArgType_int for array in struct (#8002)
1 parent bd521ed commit 11ac737

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/checkio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ CheckIO::ArgumentInfo::ArgumentInfo(const Token * arg, const Settings &settings,
13991399
for (int p = 0; p < valuetype->pointer; p++)
14001400
tempToken->insertToken("*");
14011401
tempToken = const_cast<Token*>(typeToken);
1402-
if (top->isBinaryOp() && valuetype->pointer == 1 && (valuetype->type == ValueType::CHAR || valuetype->type == ValueType::WCHAR_T))
1402+
if (top->isBinaryOp() && Token::Match(top, "[+-]") && valuetype->pointer == 1 && (valuetype->type == ValueType::CHAR || valuetype->type == ValueType::WCHAR_T))
14031403
tempToken->tokType(Token::eString);
14041404
return;
14051405
}

test/testio.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2186,6 +2186,12 @@ class TestIO : public TestFixture {
21862186
" scanf(\"%i\", \"abc\" + 1);\n"
21872187
"}\n");
21882188
ASSERT_EQUALS("[test.cpp:2]: (warning) %i in format string (no. 1) requires 'int *' but the argument type is 'const char *'.\n", errout_str());
2189+
2190+
check("struct S { unsigned char a[1]; };" // #14302
2191+
"void f(S s) {\n"
2192+
" scanf(\"%hhu\", s.a);\n"
2193+
"}\n");
2194+
ASSERT_EQUALS("", errout_str());
21892195
}
21902196

21912197
void testPrintfArgument() {

0 commit comments

Comments
 (0)