From 04d64c3e0fe60a25b1f1a5c2eaf7e2986d2130dd Mon Sep 17 00:00:00 2001 From: Jack Lloyd Date: Tue, 3 Oct 2017 00:38:15 -0400 Subject: Add wrappers for reinterpret_cast between char* and uint8_t* Generally speaking reinterpret_cast is sketchy stuff. But the special case of char*/uint8_t* is both common and safe. By isolating those, the remaining (likely sketchy) cases are easier to grep for. --- src/lib/math/bigint/big_code.cpp | 6 +++--- src/lib/math/bigint/big_io.cpp | 2 +- src/lib/math/bigint/bigint.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src/lib/math') diff --git a/src/lib/math/bigint/big_code.cpp b/src/lib/math/bigint/big_code.cpp index f7ab53291..c42819965 100644 --- a/src/lib/math/bigint/big_code.cpp +++ b/src/lib/math/bigint/big_code.cpp @@ -26,7 +26,7 @@ void BigInt::encode(uint8_t output[], const BigInt& n, Base base) secure_vector binary(n.encoded_size(Binary)); n.binary_encode(binary.data()); - hex_encode(reinterpret_cast(output), + hex_encode(cast_uint8_ptr_to_char(output), binary.data(), binary.size()); } else if(base == Decimal) @@ -128,12 +128,12 @@ BigInt BigInt::decode(const uint8_t buf[], size_t length, Base base) binary = hex_decode_locked(buf0_with_leading_0, 2); - binary += hex_decode_locked(reinterpret_cast(&buf[1]), + binary += hex_decode_locked(cast_uint8_ptr_to_char(&buf[1]), length - 1, false); } else - binary = hex_decode_locked(reinterpret_cast(buf), + binary = hex_decode_locked(cast_uint8_ptr_to_char(buf), length, false); r.binary_decode(binary.data(), binary.size()); diff --git a/src/lib/math/bigint/big_io.cpp b/src/lib/math/bigint/big_io.cpp index 7d990e25e..803e1cc4a 100644 --- a/src/lib/math/bigint/big_io.cpp +++ b/src/lib/math/bigint/big_io.cpp @@ -32,7 +32,7 @@ std::ostream& operator<<(std::ostream& stream, const BigInt& n) size_t skip = 0; while(skip < buffer.size() && buffer[skip] == '0') ++skip; - stream.write(reinterpret_cast(buffer.data()) + skip, + stream.write(cast_uint8_ptr_to_char(buffer.data()) + skip, buffer.size() - skip); } if(!stream.good()) diff --git a/src/lib/math/bigint/bigint.cpp b/src/lib/math/bigint/bigint.cpp index 47ff2482a..28fe68f00 100644 --- a/src/lib/math/bigint/bigint.cpp +++ b/src/lib/math/bigint/bigint.cpp @@ -68,7 +68,7 @@ BigInt::BigInt(const std::string& str) base = Hexadecimal; } - *this = decode(reinterpret_cast(str.data()) + markers, + *this = decode(cast_char_ptr_to_uint8(str.data()) + markers, str.length() - markers, base); if(negative) set_sign(Negative); -- cgit v1.2.3