Use std::make_unsigned<OPJ_OFF_T>::type in JPX code.
Remove a long standing FIXME that depended on the ability to use C++11.
Change-Id: Ia4f167ef72baea25c569e7030f8452412a0c0658
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/53432
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcodec/codec/ccodec_jpxmodule.cpp b/core/fxcodec/codec/ccodec_jpxmodule.cpp
index 0e82b7f..431bd27 100644
--- a/core/fxcodec/codec/ccodec_jpxmodule.cpp
+++ b/core/fxcodec/codec/ccodec_jpxmodule.cpp
@@ -9,6 +9,7 @@
#include <algorithm>
#include <limits>
#include <memory>
+#include <type_traits>
#include <utility>
#include <vector>
@@ -278,22 +279,22 @@
if (nb_bytes < 0)
return static_cast<OPJ_OFF_T>(-1);
- // FIXME: use std::make_unsigned<OPJ_OFF_T>::type once c++11 lib is OK'd.
- uint64_t unsignedNbBytes = static_cast<uint64_t>(nb_bytes);
+ auto unsigned_nb_bytes =
+ static_cast<std::make_unsigned<OPJ_OFF_T>::type>(nb_bytes);
// Additionally, the offset may take us beyond the range of a size_t (e.g.
// 32-bit platforms). If so, just clamp at EOF.
- if (unsignedNbBytes >
+ if (unsigned_nb_bytes >
std::numeric_limits<OPJ_SIZE_T>::max() - srcData->offset) {
srcData->offset = srcData->src_size;
} else {
- OPJ_SIZE_T checkedNbBytes = static_cast<OPJ_SIZE_T>(unsignedNbBytes);
+ OPJ_SIZE_T checked_nb_bytes = static_cast<OPJ_SIZE_T>(unsigned_nb_bytes);
// Otherwise, mimic fseek() semantics to always succeed, even past EOF,
// clamping at EOF. We can get away with this since we don't actually
// provide negative relative skips from beyond EOF back to inside the
// data, which would be the only reason to need to know exactly how far
// beyond EOF we are.
srcData->offset =
- std::min(srcData->offset + checkedNbBytes, srcData->src_size);
+ std::min(srcData->offset + checked_nb_bytes, srcData->src_size);
}
return nb_bytes;
}
@@ -308,17 +309,17 @@
if (nb_bytes < 0)
return OPJ_FALSE;
- // FIXME: use std::make_unsigned<OPJ_OFF_T>::type once c++11 lib is OK'd.
- uint64_t unsignedNbBytes = static_cast<uint64_t>(nb_bytes);
+ auto unsigned_nb_bytes =
+ static_cast<std::make_unsigned<OPJ_OFF_T>::type>(nb_bytes);
// Additionally, the offset may take us beyond the range of a size_t (e.g.
// 32-bit platforms). If so, just clamp at EOF.
- if (unsignedNbBytes > std::numeric_limits<OPJ_SIZE_T>::max()) {
+ if (unsigned_nb_bytes > std::numeric_limits<OPJ_SIZE_T>::max()) {
srcData->offset = srcData->src_size;
} else {
- OPJ_SIZE_T checkedNbBytes = static_cast<OPJ_SIZE_T>(nb_bytes);
+ OPJ_SIZE_T checked_nb_bytes = static_cast<OPJ_SIZE_T>(nb_bytes);
// Otherwise, mimic fseek() semantics to always succeed, even past EOF,
// again clamping at EOF.
- srcData->offset = std::min(checkedNbBytes, srcData->src_size);
+ srcData->offset = std::min(checked_nb_bytes, srcData->src_size);
}
return OPJ_TRUE;
}