checkType: Take into account the size of char.
This commit is contained in:
parent
feef8f3ebe
commit
50844aa7fc
|
@ -804,7 +804,7 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck, int /*argc*/, const cha
|
|||
{
|
||||
Settings& settings = cppcheck.settings();
|
||||
_settings = &settings;
|
||||
bool std = tryLoadLibrary(settings.library, argv[0], "std.cfg");
|
||||
const bool std = tryLoadLibrary(settings.library, argv[0], "std.cfg");
|
||||
bool posix = true;
|
||||
if (settings.standards.posix)
|
||||
posix = tryLoadLibrary(settings.library, argv[0], "posix.cfg");
|
||||
|
|
|
@ -69,11 +69,13 @@ void CheckType::checkTooBigBitwiseShift()
|
|||
continue;
|
||||
|
||||
// get number of bits of lhs
|
||||
const ValueType *lhstype = tok->astOperand1()->valueType();
|
||||
const ValueType * const lhstype = tok->astOperand1()->valueType();
|
||||
if (!lhstype || !lhstype->isIntegral() || lhstype->pointer >= 1U)
|
||||
continue;
|
||||
int lhsbits = 0;
|
||||
if (lhstype->type <= ValueType::Type::INT)
|
||||
if (lhstype->type == ValueType::Type::CHAR)
|
||||
lhsbits = _settings->char_bit;
|
||||
else if (lhstype->type <= ValueType::Type::INT)
|
||||
lhsbits = _settings->int_bit;
|
||||
else if (lhstype->type == ValueType::Type::LONG)
|
||||
lhsbits = _settings->long_bit;
|
||||
|
|
|
@ -65,6 +65,11 @@ private:
|
|||
Settings settings;
|
||||
settings.platform(Settings::Unix32);
|
||||
|
||||
check("char foo(char x) {\n"
|
||||
" return x << 32;\n"
|
||||
"}",&settings);
|
||||
ASSERT_EQUALS("[test.cpp:2]: (error) Shifting 8-bit value by 32 bits is undefined behaviour\n", errout.str());
|
||||
|
||||
check("int foo(unsigned int x) {\n"
|
||||
" return x << 32;\n"
|
||||
"}",&settings);
|
||||
|
|
Loading…
Reference in New Issue