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/ffi | |
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/ffi')
-rw-r--r-- | src/lib/ffi/ffi_mp.cpp | 2 | ||||
-rw-r--r-- | src/lib/ffi/ffi_util.h | 9 |
2 files changed, 6 insertions, 5 deletions
diff --git a/src/lib/ffi/ffi_mp.cpp b/src/lib/ffi/ffi_mp.cpp index 00ad786ab..0b55c1d69 100644 --- a/src/lib/ffi/ffi_mp.cpp +++ b/src/lib/ffi/ffi_mp.cpp @@ -63,7 +63,7 @@ int botan_mp_set_from_radix_str(botan_mp_t mp, const char* str, size_t radix) else return BOTAN_FFI_ERROR_NOT_IMPLEMENTED; - const uint8_t* bytes = reinterpret_cast<const uint8_t*>(str); + const uint8_t* bytes = Botan::cast_char_ptr_to_uint8(str); const size_t len = strlen(str); bn = Botan::BigInt::decode(bytes, len, base); diff --git a/src/lib/ffi/ffi_util.h b/src/lib/ffi/ffi_util.h index ae48ab01a..b52c319fe 100644 --- a/src/lib/ffi/ffi_util.h +++ b/src/lib/ffi/ffi_util.h @@ -176,19 +176,20 @@ int write_vec_output(uint8_t out[], size_t* out_len, const std::vector<uint8_t, inline int write_str_output(uint8_t out[], size_t* out_len, const std::string& str) { return write_output(out, out_len, - reinterpret_cast<const uint8_t*>(str.c_str()), + Botan::cast_char_ptr_to_uint8(str.data()), str.size() + 1); } inline int write_str_output(char out[], size_t* out_len, const std::string& str) { - return write_str_output(reinterpret_cast<uint8_t*>(out), out_len, str); + return write_str_output(Botan::cast_char_ptr_to_uint8(out), out_len, str); } inline int write_str_output(char out[], size_t* out_len, const std::vector<uint8_t>& str_vec) { - return write_output(reinterpret_cast<uint8_t*>(out), out_len, - reinterpret_cast<const uint8_t*>(str_vec.data()), + return write_output(Botan::cast_char_ptr_to_uint8(out), + out_len, + str_vec.data(), str_vec.size()); } |