Platform: Fix type limits calculations. sizeof=>bit
This commit is contained in:
parent
c70987b727
commit
5175bf88d6
|
@ -34,27 +34,27 @@ namespace cppcheck {
|
||||||
*/
|
*/
|
||||||
class CPPCHECKLIB Platform {
|
class CPPCHECKLIB Platform {
|
||||||
private:
|
private:
|
||||||
long long min_value(int sz) const {
|
long long min_value(int bit) const {
|
||||||
if (sz >= 64)
|
if (bit >= 64)
|
||||||
return 1LL << 63;
|
return 1LL << 63;
|
||||||
return -(1LL << (sz-1));
|
return -(1LL << (bit-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
long long max_value(int sz) const {
|
long long max_value(int bit) const {
|
||||||
if (sz >= 64)
|
if (bit >= 64)
|
||||||
return (~0ULL) >> 1;
|
return (~0ULL) >> 1;
|
||||||
return (1LL << (sz-1)) - 1LL;
|
return (1LL << (bit-1)) - 1LL;
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
Platform();
|
Platform();
|
||||||
virtual ~Platform() {}
|
virtual ~Platform() {}
|
||||||
|
|
||||||
bool isIntValue(long long value) const {
|
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 {
|
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
|
unsigned int char_bit; /// bits in char
|
||||||
|
|
|
@ -3862,9 +3862,9 @@ private:
|
||||||
ASSERT_EQUALS("", ValueType().str());
|
ASSERT_EQUALS("", ValueType().str());
|
||||||
|
|
||||||
Settings s;
|
Settings s;
|
||||||
s.sizeof_int = 16;
|
s.int_bit = 16;
|
||||||
s.sizeof_long = 32;
|
s.long_bit = 32;
|
||||||
s.sizeof_long_long = 64;
|
s.long_long_bit = 64;
|
||||||
|
|
||||||
// numbers
|
// numbers
|
||||||
ASSERT_EQUALS("signed int", typeOf("1", "1", "test.c", &s));
|
ASSERT_EQUALS("signed int", typeOf("1", "1", "test.c", &s));
|
||||||
|
|
Loading…
Reference in New Issue