Make exceptions use of LEB decoder valgrind clean.

Bug: 11670287
Change-Id: I0c11c710d03e08559e0032bf602cf7cf13c92da9
diff --git a/runtime/mapping_table.h b/runtime/mapping_table.h
index 9955f30..c468c1e 100644
--- a/runtime/mapping_table.h
+++ b/runtime/mapping_table.h
@@ -30,7 +30,7 @@
 
   uint32_t TotalSize() const PURE {
     const uint8_t* table = encoded_table_;
-    if (table == NULL) {
+    if (table == nullptr) {
       return 0;
     } else {
       return DecodeUnsignedLeb128(&table);
@@ -39,7 +39,7 @@
 
   uint32_t DexToPcSize() const PURE {
     const uint8_t* table = encoded_table_;
-    if (table == NULL) {
+    if (table == nullptr) {
       return 0;
     } else {
       uint32_t total_size = DecodeUnsignedLeb128(&table);
@@ -50,9 +50,11 @@
 
   const uint8_t* FirstDexToPcPtr() const {
     const uint8_t* table = encoded_table_;
-    if (table != NULL) {
-      DecodeUnsignedLeb128(&table);  // Total_size, unused.
+    if (table != nullptr) {
+      uint32_t total_size = DecodeUnsignedLeb128(&table);
       uint32_t pc_to_dex_size = DecodeUnsignedLeb128(&table);
+      // We must have dex to pc entries or else the loop will go beyond the end of the table.
+      DCHECK_GT(total_size, pc_to_dex_size);
       for (uint32_t i = 0; i < pc_to_dex_size; ++i) {
         DecodeUnsignedLeb128(&table);  // Move ptr past native PC.
         DecodeUnsignedLeb128(&table);  // Move ptr past dex PC.
@@ -64,15 +66,15 @@
   class DexToPcIterator {
    public:
     DexToPcIterator(const MappingTable* table, uint32_t element) :
-        table_(table), element_(element), end_(table_->DexToPcSize()), encoded_table_ptr_(NULL),
+        table_(table), element_(element), end_(table_->DexToPcSize()), encoded_table_ptr_(nullptr),
         native_pc_offset_(0), dex_pc_(0) {
-      if (element == 0) {
-        encoded_table_ptr_ = table_->FirstDexToPcPtr();
+      if (element == 0) {  // An iterator wanted from the start.
         if (end_ > 0) {
+          encoded_table_ptr_ = table_->FirstDexToPcPtr();
           native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
           dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
         }
-      } else {
+      } else {  // An iterator wanted from the end.
         DCHECK_EQ(table_->DexToPcSize(), element);
       }
     }
@@ -102,7 +104,7 @@
     const MappingTable* const table_;  // The original table.
     uint32_t element_;  // A value in the range 0 to end_.
     const uint32_t end_;  // Equal to table_->DexToPcSize().
-    const uint8_t* encoded_table_ptr_;  // Either NULL or points to encoded data after this entry.
+    const uint8_t* encoded_table_ptr_;  // Either nullptr or points to encoded data after this entry.
     uint32_t native_pc_offset_;  // The current value of native pc offset.
     uint32_t dex_pc_;  // The current value of dex pc.
   };
@@ -118,7 +120,7 @@
 
   uint32_t PcToDexSize() const PURE {
     const uint8_t* table = encoded_table_;
-    if (table == NULL) {
+    if (table == nullptr) {
       return 0;
     } else {
       DecodeUnsignedLeb128(&table);  // Total_size, unused.
@@ -129,7 +131,7 @@
 
   const uint8_t* FirstPcToDexPtr() const {
     const uint8_t* table = encoded_table_;
-    if (table != NULL) {
+    if (table != nullptr) {
       DecodeUnsignedLeb128(&table);  // Total_size, unused.
       DecodeUnsignedLeb128(&table);  // PC to Dex size, unused.
     }
@@ -139,15 +141,15 @@
   class PcToDexIterator {
    public:
     PcToDexIterator(const MappingTable* table, uint32_t element) :
-        table_(table), element_(element), end_(table_->PcToDexSize()), encoded_table_ptr_(NULL),
+        table_(table), element_(element), end_(table_->PcToDexSize()), encoded_table_ptr_(nullptr),
         native_pc_offset_(0), dex_pc_(0) {
-      if (element == 0) {
-        encoded_table_ptr_ = table_->FirstPcToDexPtr();
+      if (element == 0) {  // An iterator wanted from the start.
         if (end_ > 0) {
+          encoded_table_ptr_ = table_->FirstPcToDexPtr();
           native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
           dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
         }
-      } else {
+      } else {  // An iterator wanted from the end.
         DCHECK_EQ(table_->PcToDexSize(), element);
       }
     }
@@ -177,7 +179,7 @@
     const MappingTable* const table_;  // The original table.
     uint32_t element_;  // A value in the range 0 to PcToDexSize.
     const uint32_t end_;  // Equal to table_->PcToDexSize().
-    const uint8_t* encoded_table_ptr_;  // Either NULL or points to encoded data after this entry.
+    const uint8_t* encoded_table_ptr_;  // Either null or points to encoded data after this entry.
     uint32_t native_pc_offset_;  // The current value of native pc offset.
     uint32_t dex_pc_;  // The current value of dex pc.
   };