Skip to content

Commit eb076d8

Browse files
authored
Improve testcases for unsigned char platforms (#5524)
I got error messages while building `cppcheck 2.12.0` for RISC-V Arch Linux: ``` Testing Complete Number of tests: 4420 Number of todos: 331 Tests failed: 2 /usr/src/debug/cppcheck/cppcheck/test/testcondition.cpp:4501(TestCondition::alwaysTrue): Assertion failed. Expected: [test.cpp:6]: (style) Condition 'o[1]=='\0'' is always false\n Actual: [test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\0'' is always false\n _____ /usr/src/debug/cppcheck/cppcheck/test/testcondition.cpp:5014(TestCondition::alwaysTrueContainer): Assertion failed. Expected: [test.cpp:5]: (style) Condition 'buffer.back()=='\0'' is always false\n Actual: [test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\0'' is always false\n ``` I found out the reason is that the testcases were designed for x86/x86_64 or other `signed char` platforms (i.e. default character type is `signed char` ), whereareas RISC-V is an `unsigned char` platform, which causes different behavior in `lib/valueflow.cpp:valueFlowImpossibleValues`. I'm not sure whether this error leads from a functional bug, so if you have a better approach to fix it, please let me know. Maybe you could reproduce this error on x86_64 platform by setting `defaultSign = 'u';` in `Platform::set(Type t)`.
1 parent e9c39c1 commit eb076d8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

test/testcondition.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4498,7 +4498,11 @@ class TestCondition : public TestFixture {
44984498
" if (o[1] == '\\0') {}\n"
44994499
" }\n"
45004500
"}\n");
4501-
ASSERT_EQUALS("[test.cpp:6]: (style) Condition 'o[1]=='\\0'' is always false\n", errout.str());
4501+
if (std::numeric_limits<char>::is_signed) {
4502+
ASSERT_EQUALS("[test.cpp:6]: (style) Condition 'o[1]=='\\0'' is always false\n", errout.str());
4503+
} else {
4504+
ASSERT_EQUALS("[test.cpp:4] -> [test.cpp:6]: (style) Condition 'o[1]=='\\0'' is always false\n", errout.str());
4505+
}
45024506

45034507
check("void f(int x) {\n" // #11449
45044508
" int i = x;\n"
@@ -5016,7 +5020,11 @@ class TestCondition : public TestFixture {
50165020
" buffer.back() == '\\n' ||\n"
50175021
" buffer.back() == '\\0') {}\n"
50185022
"}\n");
5019-
ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'buffer.back()=='\\0'' is always false\n", errout.str());
5023+
if (std::numeric_limits<char>::is_signed) {
5024+
ASSERT_EQUALS("[test.cpp:5]: (style) Condition 'buffer.back()=='\\0'' is always false\n", errout.str());
5025+
} else {
5026+
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:5]: (style) Condition 'buffer.back()=='\\0'' is always false\n", errout.str());
5027+
}
50205028

50215029
// #9353
50225030
check("typedef struct { std::string s; } X;\n"

0 commit comments

Comments
 (0)