diff options
author | lloyd <[email protected]> | 2007-07-23 15:44:04 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2007-07-23 15:44:04 +0000 |
commit | e2f1f734277146d817ab284dea21e4013cb5b937 (patch) | |
tree | 21ad6ee775e36aa7fb24a504077200c22b1f15b8 /include | |
parent | 211c4929ae92106794984d872a0cae1a873baa29 (diff) |
Avoid C-style casts (as detected by GCC's -Wold-style-cast) and instead use
static_cast or reinterpret_cast, as needed.
Diffstat (limited to 'include')
-rw-r--r-- | include/bit_ops.h | 8 | ||||
-rw-r--r-- | include/loadstor.h | 38 | ||||
-rw-r--r-- | include/mp_types.h | 4 | ||||
-rw-r--r-- | include/secmem.h | 6 |
4 files changed, 38 insertions, 18 deletions
diff --git a/include/bit_ops.h b/include/bit_ops.h index 4b8d248d6..5883d2163 100644 --- a/include/bit_ops.h +++ b/include/bit_ops.h @@ -15,10 +15,14 @@ namespace Botan { * Word Rotation Functions * *************************************************/ template<typename T> inline T rotate_left(T input, u32bit rot) - { return (T)((input << rot) | (input >> (8*sizeof(T)-rot))); } + { + return static_cast<T>((input << rot) | (input >> (8*sizeof(T)-rot)));; + } template<typename T> inline T rotate_right(T input, u32bit rot) - { return (T)((input >> rot) | (input << (8*sizeof(T)-rot))); } + { + return static_cast<T>((input >> rot) | (input << (8*sizeof(T)-rot))); + } /************************************************* * XOR Functions * diff --git a/include/loadstor.h b/include/loadstor.h index f9ce7417f..992a71afe 100644 --- a/include/loadstor.h +++ b/include/loadstor.h @@ -14,27 +14,39 @@ namespace Botan { * Byte Extraction Function * *************************************************/ template<typename T> inline byte get_byte(u32bit byte_num, T input) - { return (byte)(input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3)); } + { + return (input >> ((sizeof(T)-1-(byte_num&(sizeof(T)-1))) << 3)); + } /************************************************* * Byte to Word Conversions * *************************************************/ -inline u16bit make_u16bit(byte input0, byte input1) - { return (u16bit)(((u16bit)input0 << 8) | input1); } - -inline u32bit make_u32bit(byte input0, byte input1, byte input2, byte input3) - { return (u32bit)(((u32bit)input0 << 24) | ((u32bit)input1 << 16) | - ((u32bit)input2 << 8) | input3); } +inline u16bit make_u16bit(byte i0, byte i1) + { + return ((static_cast<u16bit>(i0) << 8) | i1); + } -inline u64bit make_u64bit(byte input0, byte input1, byte input2, byte input3, - byte input4, byte input5, byte input6, byte input7) +inline u32bit make_u32bit(byte i0, byte i1, byte i2, byte i3) { - return (u64bit)(((u64bit)input0 << 56) | ((u64bit)input1 << 48) | - ((u64bit)input2 << 40) | ((u64bit)input3 << 32) | - ((u64bit)input4 << 24) | ((u64bit)input5 << 16) | - ((u64bit)input6 << 8) | input7); + return ((static_cast<u32bit>(i0) << 24) | + (static_cast<u32bit>(i1) << 16) | + (static_cast<u32bit>(i2) << 8) | + (static_cast<u32bit>(i3))); } +inline u64bit make_u64bit(byte i0, byte i1, byte i2, byte i3, + byte i4, byte i5, byte i6, byte i7) + { + return ((static_cast<u64bit>(i0) << 56) | + (static_cast<u64bit>(i1) << 48) | + (static_cast<u64bit>(i2) << 40) | + (static_cast<u64bit>(i3) << 32) | + (static_cast<u64bit>(i4) << 24) | + (static_cast<u64bit>(i5) << 16) | + (static_cast<u64bit>(i6) << 8) | + (static_cast<u64bit>(i7))); + } + /************************************************* * Endian-Specific Word Loading Operations * *************************************************/ diff --git a/include/mp_types.h b/include/mp_types.h index ed68a4ba1..8ba551bd8 100644 --- a/include/mp_types.h +++ b/include/mp_types.h @@ -22,8 +22,8 @@ namespace Botan { #error BOTAN_MP_WORD_BITS must be 8, 16, 32, or 64 #endif -const word MP_WORD_MASK = ~((word)0); -const word MP_WORD_TOP_BIT = (word)1 << (8*sizeof(word) - 1); +const word MP_WORD_MASK = ~static_cast<word>(0); +const word MP_WORD_TOP_BIT = static_cast<word>(1) << (8*sizeof(word) - 1); const word MP_WORD_MAX = MP_WORD_MASK; } diff --git a/include/secmem.h b/include/secmem.h index 2b5e046f8..b50022c83 100644 --- a/include/secmem.h +++ b/include/secmem.h @@ -78,7 +78,11 @@ class MemoryRegion void init(bool locking, u32bit size = 0) { alloc = Allocator::get(locking); create(size); } private: - T* allocate(u32bit n) const { return (T*)alloc->allocate(sizeof(T)*n); } + T* allocate(u32bit n) const + { + return static_cast<T*>(alloc->allocate(sizeof(T)*n)); + } + void deallocate(T* p, u32bit n) const { alloc->deallocate(p, sizeof(T)*n); } |