diff options
-rw-r--r-- | libunwind/src/DwarfParser.hpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/libunwind/src/DwarfParser.hpp b/libunwind/src/DwarfParser.hpp index 518101edcf1..645ac217a3d 100644 --- a/libunwind/src/DwarfParser.hpp +++ b/libunwind/src/DwarfParser.hpp @@ -17,7 +17,6 @@ #include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <limits.h> #include "libunwind.h" #include "dwarf2.h" @@ -26,6 +25,10 @@ namespace libunwind { +// Avoid relying on C++ headers. +template <class T> +static constexpr T pint_max_value() { return ~0; } + /// CFI_Parser does basic parsing of a CFI (Call Frame Information) records. /// See DWARF Spec for details: /// http://refspecs.linuxbase.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/ehframechpt.html @@ -540,7 +543,7 @@ bool CFI_Parser<A>::parseInstructions(A &addressSpace, pint_t instructions, results->cfaRegister = 0; results->cfaExpression = (int64_t)p; length = addressSpace.getULEB128(p, instructionsEnd); - assert(length < std::numeric_limits<pint_t>::max() && "pointer overflow"); + assert(length < pint_max_value<pint_t>() && "pointer overflow"); p += static_cast<pint_t>(length); _LIBUNWIND_TRACE_DWARF("DW_CFA_def_cfa_expression(expression=0x%" PRIx64 ", length=%" PRIu64 ")\n", @@ -556,7 +559,7 @@ bool CFI_Parser<A>::parseInstructions(A &addressSpace, pint_t instructions, results->savedRegisters[reg].location = kRegisterAtExpression; results->savedRegisters[reg].value = (int64_t)p; length = addressSpace.getULEB128(p, instructionsEnd); - assert(length < std::numeric_limits<pint_t>::max() && "pointer overflow"); + assert(length < pint_max_value<pint_t>() && "pointer overflow"); p += static_cast<pint_t>(length); _LIBUNWIND_TRACE_DWARF("DW_CFA_expression(reg=%" PRIu64 ", " "expression=0x%" PRIx64 ", " @@ -642,7 +645,7 @@ bool CFI_Parser<A>::parseInstructions(A &addressSpace, pint_t instructions, results->savedRegisters[reg].location = kRegisterIsExpression; results->savedRegisters[reg].value = (int64_t)p; length = addressSpace.getULEB128(p, instructionsEnd); - assert(length < std::numeric_limits<pint_t>::max() && "pointer overflow"); + assert(length < pint_max_value<pint_t>() && "pointer overflow"); p += static_cast<pint_t>(length); _LIBUNWIND_TRACE_DWARF("DW_CFA_val_expression(reg=%" PRIu64 ", " "expression=0x%" PRIx64 ", length=%" PRIu64 ")\n", |