From 27c3f9de5bdccd63e2ae088e69d6af23c4fa33a7 Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Thu, 29 Feb 2024 05:35:24 -0800 Subject: [PATCH] Fix some shift-sign-overflow --- libredex/DexOutput.h | 6 +++--- libresource/androidfw/ResourceTypes.h | 2 +- opt/result-propagation/ResultPropagation.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libredex/DexOutput.h b/libredex/DexOutput.h index 1fe85e8377..2eb18033f8 100644 --- a/libredex/DexOutput.h +++ b/libredex/DexOutput.h @@ -313,11 +313,11 @@ class DexOutput { enhanced_dex_stats_t m_stats; static constexpr size_t kIODILayerBits = 4; - static constexpr size_t kIODILayerBound = 1 << (kIODILayerBits - 1); + static constexpr size_t kIODILayerBound = 1ul << (kIODILayerBits - 1); static constexpr size_t kIODILayerShift = sizeof(uint32_t) * 8 - kIODILayerBits; - static constexpr uint32_t kIODIDataMask = (1 << kIODILayerShift) - 1; - static constexpr uint32_t kIODILayerMask = ((1 << kIODILayerBits) - 1) + static constexpr uint32_t kIODIDataMask = (1u << kIODILayerShift) - 1; + static constexpr uint32_t kIODILayerMask = ((1u << kIODILayerBits) - 1) << kIODILayerShift; private: diff --git a/libresource/androidfw/ResourceTypes.h b/libresource/androidfw/ResourceTypes.h index dbc3a2622a..1097a65d29 100644 --- a/libresource/androidfw/ResourceTypes.h +++ b/libresource/androidfw/ResourceTypes.h @@ -237,7 +237,7 @@ struct Res_value // Where the actual value is. This gives us 23 bits of // precision. The top bit is the sign. COMPLEX_MANTISSA_SHIFT = 8, - COMPLEX_MANTISSA_MASK = 0xffffff + COMPLEX_MANTISSA_MASK = 0xffffffU }; // Possible data values for TYPE_NULL. diff --git a/opt/result-propagation/ResultPropagation.cpp b/opt/result-propagation/ResultPropagation.cpp index 66bf226745..1015519511 100644 --- a/opt/result-propagation/ResultPropagation.cpp +++ b/opt/result-propagation/ResultPropagation.cpp @@ -34,7 +34,7 @@ constexpr const char* METRIC_UNVERIFIABLE_MOVE_RESULTS = "num_unverifiable_move_results"; constexpr const char* METRIC_METHODS_WHICH_RETURN_PARAMETER_ITERATIONS = "num_methods_which_return_parameters_iterations"; -constexpr const ParamIndex WIDE_HIGH = 1 << 31; +constexpr const ParamIndex WIDE_HIGH = 1u << 31; void patch_move_result_to_move(IRInstruction* move_result_inst, reg_t reg) { const auto op = move_result_inst->opcode();