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 = cppcheck.settings();
|
||||||
_settings = &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;
|
bool posix = true;
|
||||||
if (settings.standards.posix)
|
if (settings.standards.posix)
|
||||||
posix = tryLoadLibrary(settings.library, argv[0], "posix.cfg");
|
posix = tryLoadLibrary(settings.library, argv[0], "posix.cfg");
|
||||||
|
|
|
@ -69,11 +69,13 @@ void CheckType::checkTooBigBitwiseShift()
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// get number of bits of lhs
|
// 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)
|
if (!lhstype || !lhstype->isIntegral() || lhstype->pointer >= 1U)
|
||||||
continue;
|
continue;
|
||||||
int lhsbits = 0;
|
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;
|
lhsbits = _settings->int_bit;
|
||||||
else if (lhstype->type == ValueType::Type::LONG)
|
else if (lhstype->type == ValueType::Type::LONG)
|
||||||
lhsbits = _settings->long_bit;
|
lhsbits = _settings->long_bit;
|
||||||
|
|
|
@ -65,6 +65,11 @@ private:
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.platform(Settings::Unix32);
|
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"
|
check("int foo(unsigned int x) {\n"
|
||||||
" return x << 32;\n"
|
" return x << 32;\n"
|
||||||
"}",&settings);
|
"}",&settings);
|
||||||
|
|
Loading…
Reference in New Issue