diff options
author | Colin Snover | 2017-01-07 15:44:06 -0600 |
---|---|---|
committer | Colin Snover | 2017-01-08 13:21:10 -0600 |
commit | b2796e65aa306f572978b5ade8343ce1357b4c04 (patch) | |
tree | 4913eb8cf5d6b5d8129e5e59a7019ade6c0d1b9f /common | |
parent | 2558b20cdda438bb0816791b1193776ff55aefde (diff) | |
download | scummvm-rg350-b2796e65aa306f572978b5ade8343ce1357b4c04.tar.gz scummvm-rg350-b2796e65aa306f572978b5ade8343ce1357b4c04.tar.bz2 scummvm-rg350-b2796e65aa306f572978b5ade8343ce1357b4c04.zip |
COMMON: Restrict use of data access helpers
The data access helpers as written are effectively little-endian
when reading from spans with value_types larger than the size of
the requested data (e.g. more than 1 byte for getting a char,
more than 2 bytes for getting a uint16, etc.). For now, restrict
use of these methods at compile time until someone actually needs
to read memory that way.
Diffstat (limited to 'common')
-rw-r--r-- | common/span.h | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/common/span.h b/common/span.h index bbfa658807..c0c2ffcda4 100644 --- a/common/span.h +++ b/common/span.h @@ -314,62 +314,74 @@ public: } inline int8 getInt8At(const index_type index) const { + STATIC_ASSERT(sizeof(value_type) == sizeof(uint8), int8_can_only_be_read_from_byte_or_char_spans); return (int8)getUint8At(index); } inline uint8 getUint8At(const index_type index) const { + STATIC_ASSERT(sizeof(value_type) == sizeof(uint8), uint8_can_only_be_read_from_byte_or_char_spans); impl().validate(index, sizeof(uint8)); return (uint8)impl().data()[index]; } inline int16 getInt16BEAt(const index_type index) const { + STATIC_ASSERT(sizeof(value_type) <= sizeof(uint16), int16_can_only_be_read_from_int16_or_smaller_spans); return (int16)impl().getUint16BEAt(index); } inline int16 getInt16LEAt(const index_type index) const { + STATIC_ASSERT(sizeof(value_type) <= sizeof(uint16), int16_can_only_be_read_from_int16_or_smaller_spans); return (int16)impl().getUint16LEAt(index); } inline uint16 getUint16BEAt(const index_type index) const { + STATIC_ASSERT(sizeof(value_type) <= sizeof(uint16), uint16_can_only_be_read_from_int16_or_smaller_spans); impl().validate(index, sizeof(uint16)); return READ_BE_UINT16(impl().data() + index); } inline uint16 getUint16LEAt(const index_type index) const { + STATIC_ASSERT(sizeof(value_type) <= sizeof(uint16), uint16_can_only_be_read_from_int16_or_smaller_spans); impl().validate(index, sizeof(uint16)); return READ_LE_UINT16(impl().data() + index); } inline uint32 getUint24LEAt(const index_type index) const { + STATIC_ASSERT(sizeof(value_type) <= 3, uint24_can_only_be_read_from_int24_or_smaller_spans); impl().validate(index, 3); return READ_LE_UINT24(impl().data() + index); } inline uint32 getUint32At(const index_type index) const { + STATIC_ASSERT(sizeof(value_type) <= sizeof(uint32), uint32_can_only_be_read_from_int32_or_smaller_spans); impl().validate(index, sizeof(uint32)); return READ_UINT32(impl().data() + index); } inline int32 getInt32BEAt(const index_type index) const { + STATIC_ASSERT(sizeof(value_type) <= sizeof(uint32), int32_can_only_be_read_from_int32_or_smaller_spans); return (int32)impl().getUint32BEAt(index); } inline int32 getInt32LEAt(const index_type index) const { + STATIC_ASSERT(sizeof(value_type) <= sizeof(uint32), int32_can_only_be_read_from_int32_or_smaller_spans); return (int32)impl().getUint32LEAt(index); } inline uint32 getUint32BEAt(const index_type index) const { + STATIC_ASSERT(sizeof(value_type) <= sizeof(uint32), uint32_can_only_be_read_from_int32_or_smaller_spans); impl().validate(index, sizeof(uint32)); return READ_BE_UINT32(impl().data() + index); } inline uint32 getUint32LEAt(const index_type index) const { + STATIC_ASSERT(sizeof(value_type) <= sizeof(uint32), uint32_can_only_be_read_from_int32_or_smaller_spans); impl().validate(index, sizeof(uint32)); return READ_LE_UINT32(impl().data() + index); } inline String getStringAt(const index_type index, size_type numEntries = kSpanMaxSize) const { - STATIC_ASSERT(sizeof(value_type) == 1, strings_can_only_be_read_from_byte_or_char_arrays); + STATIC_ASSERT(sizeof(value_type) == sizeof(char), strings_can_only_be_read_from_byte_or_char_spans); const char *string = (const char *)impl().data(); if (numEntries == kSpanMaxSize) { @@ -410,7 +422,7 @@ public: } impl().validate(index, numEntries * sizeof(value_type)); - return MemoryReadStream(impl().data() + index, numEntries, DisposeAfterUse::NO); + return MemoryReadStream(impl().data() + index, numEntries * sizeof(value_type), DisposeAfterUse::NO); } #pragma mark - |