mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Don't assume char is signed in int conversion tests (fixes #361)
This commit is contained in:
parent
8c34d67b88
commit
6d81f01476
@ -1,3 +1,7 @@
|
||||
2019-09-17 Jay Berkenbilt <ejb@ql.org>
|
||||
|
||||
* QIntC tests: don't assume char is signed. Fixes #361.
|
||||
|
||||
2019-08-31 Jay Berkenbilt <ejb@ql.org>
|
||||
|
||||
* 9.0.0: release
|
||||
|
@ -50,6 +50,13 @@ namespace QIntC // QIntC = qpdf Integer Conversion
|
||||
typedef unsigned char type;
|
||||
};
|
||||
|
||||
template <>
|
||||
class to_u<signed char>
|
||||
{
|
||||
public:
|
||||
typedef unsigned char type;
|
||||
};
|
||||
|
||||
template <>
|
||||
class to_u<short>
|
||||
{
|
||||
|
@ -32,12 +32,13 @@ int main()
|
||||
uint64_t ul1 = 1099511627776LL; // Too big for 32-bit
|
||||
uint64_t ul2 = 12345; // Fits into 32-bit
|
||||
int32_t i2 = 81; // Fits in char and uchar
|
||||
char c1 = '\xf7'; // Signed value when char
|
||||
signed char c1 = static_cast<signed char>('\xf7'); // Signed value when char
|
||||
char c2 = 'W'; // char; may be signed or unsigned
|
||||
|
||||
// Verify i1 and u1 have same bit pattern
|
||||
assert(static_cast<uint32_t>(i1) == u1);
|
||||
// Verify that we can unsafely convert between char and unsigned char
|
||||
assert(c1 == static_cast<char>(static_cast<unsigned char>(c1)));
|
||||
// Verify that we can unsafely convert between signed and unsigned char
|
||||
assert(c1 == static_cast<signed char>(static_cast<unsigned char>(c1)));
|
||||
|
||||
try_convert(true, QIntC::to_int<int32_t>, i1);
|
||||
try_convert(true, QIntC::to_uint<uint32_t>, u1);
|
||||
@ -51,7 +52,9 @@ int main()
|
||||
try_convert(false, QIntC::to_ulonglong<int32_t>, i1);
|
||||
try_convert(true, QIntC::to_char<int32_t>, i2);
|
||||
try_convert(true, QIntC::to_uchar<int32_t>, i2);
|
||||
try_convert(false, QIntC::to_uchar<char>, c1);
|
||||
try_convert(false, QIntC::to_uchar<signed char>, c1);
|
||||
try_convert(true, QIntC::to_uchar<char>, c2);
|
||||
try_convert(true, QIntC::to_char<char>, c2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -10,4 +10,6 @@ QIntC::to_offset<int32_t>(i1): -1153374643 -1153374643 PASSED
|
||||
QIntC::to_ulonglong<int32_t>(i1): integer out of range converting -1153374643 from a 4-byte signed type to a 8-byte unsigned type PASSED
|
||||
QIntC::to_char<int32_t>(i2): 81 Q PASSED
|
||||
QIntC::to_uchar<int32_t>(i2): 81 Q PASSED
|
||||
QIntC::to_uchar<char>(c1): integer out of range converting ÷ from a 1-byte signed type to a 1-byte unsigned type PASSED
|
||||
QIntC::to_uchar<signed char>(c1): integer out of range converting ÷ from a 1-byte signed type to a 1-byte unsigned type PASSED
|
||||
QIntC::to_uchar<char>(c2): W W PASSED
|
||||
QIntC::to_char<char>(c2): W W PASSED
|
||||
|
Loading…
Reference in New Issue
Block a user