[libunwind] r297291 - DARWF: silence some warnings about conversions

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 8 08:03:27 PST 2017


Author: compnerd
Date: Wed Mar  8 10:03:27 2017
New Revision: 297291

URL: http://llvm.org/viewvc/llvm-project?rev=297291&view=rev
Log:
DARWF: silence some warnings about conversions

Add a check for an overflow and explicitly cast the value.  We would
have silently overflowed previously.

Modified:
    libunwind/trunk/src/DwarfInstructions.hpp
    libunwind/trunk/src/DwarfParser.hpp

Modified: libunwind/trunk/src/DwarfInstructions.hpp
URL: http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/DwarfInstructions.hpp?rev=297291&r1=297290&r2=297291&view=diff
==============================================================================
--- libunwind/trunk/src/DwarfInstructions.hpp (original)
+++ libunwind/trunk/src/DwarfInstructions.hpp Wed Mar  8 10:03:27 2017
@@ -480,7 +480,7 @@ DwarfInstructions<A, R>::evaluateExpress
 
     case DW_OP_plus_uconst:
       // pop stack, add uelb128 constant, push result
-      *sp += addressSpace.getULEB128(p, expressionEnd);
+      *sp += static_cast<pint_t>(addressSpace.getULEB128(p, expressionEnd));
       if (log)
         fprintf(stderr, "add constant\n");
       break;

Modified: libunwind/trunk/src/DwarfParser.hpp
URL: http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/DwarfParser.hpp?rev=297291&r1=297290&r2=297291&view=diff
==============================================================================
--- libunwind/trunk/src/DwarfParser.hpp (original)
+++ libunwind/trunk/src/DwarfParser.hpp Wed Mar  8 10:03:27 2017
@@ -542,7 +542,8 @@ bool CFI_Parser<A>::parseInstructions(A
       results->cfaRegister = 0;
       results->cfaExpression = (int64_t)p;
       length = addressSpace.getULEB128(p, instructionsEnd);
-      p += length;
+      assert(length < std::numeric_limits<pint_t>::max() && "pointer overflow");
+      p += static_cast<pint_t>(length);
       _LIBUNWIND_TRACE_DWARF("DW_CFA_def_cfa_expression(expression=0x%" PRIx64
                              ", length=%" PRIu64 ")\n",
                              results->cfaExpression, length);
@@ -557,7 +558,8 @@ bool CFI_Parser<A>::parseInstructions(A
       results->savedRegisters[reg].location = kRegisterAtExpression;
       results->savedRegisters[reg].value = (int64_t)p;
       length = addressSpace.getULEB128(p, instructionsEnd);
-      p += length;
+      assert(length < std::numeric_limits<pint_t>::max() && "pointer overflow");
+      p += static_cast<pint_t>(length);
       _LIBUNWIND_TRACE_DWARF("DW_CFA_expression(reg=%" PRIu64 ", "
                              "expression=0x%" PRIx64 ", "
                              "length=%" PRIu64 ")\n",
@@ -636,7 +638,8 @@ bool CFI_Parser<A>::parseInstructions(A
       results->savedRegisters[reg].location = kRegisterIsExpression;
       results->savedRegisters[reg].value = (int64_t)p;
       length = addressSpace.getULEB128(p, instructionsEnd);
-      p += length;
+      assert(length < std::numeric_limits<pint_t>::max() && "pointer overflow");
+      p += static_cast<pint_t>(length);
       _LIBUNWIND_TRACE_DWARF("DW_CFA_val_expression(reg=%" PRIu64 ", "
                              "expression=0x%" PRIx64 ", length=%" PRIu64 ")\n",
                              reg, results->savedRegisters[reg].value, length);




More information about the cfe-commits mailing list