Platform: Fix type limits calculations. sizeof=>bit

This commit is contained in:
Daniel Marjamäki 2016-10-16 12:00:33 +02:00
parent c70987b727
commit 5175bf88d6
2 changed files with 11 additions and 11 deletions

View File

@ -34,27 +34,27 @@ namespace cppcheck {
*/
class CPPCHECKLIB Platform {
private:
long long min_value(int sz) const {
if (sz >= 64)
long long min_value(int bit) const {
if (bit >= 64)
return 1LL << 63;
return -(1LL << (sz-1));
return -(1LL << (bit-1));
}
long long max_value(int sz) const {
if (sz >= 64)
long long max_value(int bit) const {
if (bit >= 64)
return (~0ULL) >> 1;
return (1LL << (sz-1)) - 1LL;
return (1LL << (bit-1)) - 1LL;
}
public:
Platform();
virtual ~Platform() {}
bool isIntValue(long long value) const {
return value >= min_value(sizeof_int) && value <= max_value(sizeof_int);
return value >= min_value(int_bit) && value <= max_value(int_bit);
}
bool isLongValue(long long value) const {
return value >= min_value(sizeof_long) && value <= max_value(sizeof_long);
return value >= min_value(long_bit) && value <= max_value(long_bit);
}
unsigned int char_bit; /// bits in char

View File

@ -3862,9 +3862,9 @@ private:
ASSERT_EQUALS("", ValueType().str());
Settings s;
s.sizeof_int = 16;
s.sizeof_long = 32;
s.sizeof_long_long = 64;
s.int_bit = 16;
s.long_bit = 32;
s.long_long_bit = 64;
// numbers
ASSERT_EQUALS("signed int", typeOf("1", "1", "test.c", &s));