aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/qintc.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2019-09-17 18:13:19 +0200
committerJay Berkenbilt <ejb@ql.org>2019-09-17 18:18:09 +0200
commit6d81f014764e3bb9452d3697b84093bed0668f02 (patch)
treeca158b5178015b746a1f2fafaec47090e2421be6 /libtests/qintc.cc
parent8c34d67b88c3b7bccd16a3d825dab3cc55f8a8f8 (diff)
downloadqpdf-6d81f014764e3bb9452d3697b84093bed0668f02.tar.zst
Don't assume char is signed in int conversion tests (fixes #361)
Diffstat (limited to 'libtests/qintc.cc')
-rw-r--r--libtests/qintc.cc11
1 files changed, 7 insertions, 4 deletions
diff --git a/libtests/qintc.cc b/libtests/qintc.cc
index 53ec3772..6b35e837 100644
--- a/libtests/qintc.cc
+++ b/libtests/qintc.cc
@@ -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;
}