diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-04-17 23:46:18 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-17 23:46:18 +0000 |
commit | 51a41ea222eeb852be4f372165d2d9bc9094b2a4 (patch) | |
tree | 3fb5a449bc07b4fb5dde81af62836d6bfdf2a48f /core/fxcrt/fx_extension.cpp | |
parent | 11e5882fbb03bec43956ae0ea4a2a5d9593ccb34 (diff) | |
download | pdfium-51a41ea222eeb852be4f372165d2d9bc9094b2a4.tar.xz |
Use span<> in GetBits32().
Get bounds checking "for free".
Change-Id: Ic60d63836f6c223e2ee1262649d47da54bb30ecc
Reviewed-on: https://pdfium-review.googlesource.com/30876
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxcrt/fx_extension.cpp')
-rw-r--r-- | core/fxcrt/fx_extension.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp index 4448a71a9b..83aee86316 100644 --- a/core/fxcrt/fx_extension.cpp +++ b/core/fxcrt/fx_extension.cpp @@ -125,9 +125,9 @@ size_t FXSYS_ToUTF16BE(uint32_t unicode, char* buf) { return 8; } -uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) { +uint32_t GetBits32(pdfium::span<const uint8_t> pData, int bitpos, int nbits) { ASSERT(0 < nbits && nbits <= 32); - const uint8_t* dataPtr = &pData[bitpos / 8]; + size_t bytepos = bitpos / 8; int bitShift; int bitMask; int dstShift; @@ -142,16 +142,16 @@ uint32_t GetBits32(const uint8_t* pData, int bitpos, int nbits) { bitMask = (1 << std::min(bitOffset, nbits)) - 1; dstShift = nbits - bitOffset; } - uint32_t result = - static_cast<uint32_t>((*dataPtr++ >> bitShift & bitMask) << dstShift); + uint32_t result = static_cast<uint32_t>( + (pData[bytepos++] >> bitShift & bitMask) << dstShift); while (dstShift >= 8) { dstShift -= 8; - result |= *dataPtr++ << dstShift; + result |= pData[bytepos++] << dstShift; } if (dstShift > 0) { bitShift = 8 - dstShift; bitMask = (1 << dstShift) - 1; - result |= *dataPtr++ >> bitShift & bitMask; + result |= pData[bytepos++] >> bitShift & bitMask; } return result; } |