diff options
author | Jack Lloyd <[email protected]> | 2017-10-03 00:38:15 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-10-03 00:38:15 -0400 |
commit | 04d64c3e0fe60a25b1f1a5c2eaf7e2986d2130dd (patch) | |
tree | 3dc2cc7e970fc5f1cdc94887b03704d82c37e07e /src/lib/math/bigint | |
parent | 180540de74c58a72492692f58b63f32647e80bd8 (diff) |
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.
Diffstat (limited to 'src/lib/math/bigint')
-rw-r--r-- | src/lib/math/bigint/big_code.cpp | 6 | ||||
-rw-r--r-- | src/lib/math/bigint/big_io.cpp | 2 | ||||
-rw-r--r-- | src/lib/math/bigint/bigint.cpp | 2 |
3 files changed, 5 insertions, 5 deletions
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<uint8_t> binary(n.encoded_size(Binary)); n.binary_encode(binary.data()); - hex_encode(reinterpret_cast<char*>(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<const char*>(&buf[1]), + binary += hex_decode_locked(cast_uint8_ptr_to_char(&buf[1]), length - 1, false); } else - binary = hex_decode_locked(reinterpret_cast<const char*>(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<const char*>(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<const uint8_t*>(str.data()) + markers, + *this = decode(cast_char_ptr_to_uint8(str.data()) + markers, str.length() - markers, base); if(negative) set_sign(Negative); |