Avoid reading off the end of empty mapping tables.
Caught by valgrind.
Bug: 11670287
Change-Id: Ia5feacd6780e8e32c7ed600b5908c0b7d7ed7343
diff --git a/runtime/mapping_table.h b/runtime/mapping_table.h
index 2162008..9955f30 100644
--- a/runtime/mapping_table.h
+++ b/runtime/mapping_table.h
@@ -68,8 +68,10 @@
native_pc_offset_(0), dex_pc_(0) {
if (element == 0) {
encoded_table_ptr_ = table_->FirstDexToPcPtr();
- native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
- dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ if (end_ > 0) {
+ native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ }
} else {
DCHECK_EQ(table_->DexToPcSize(), element);
}
@@ -141,8 +143,10 @@
native_pc_offset_(0), dex_pc_(0) {
if (element == 0) {
encoded_table_ptr_ = table_->FirstPcToDexPtr();
- native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
- dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ if (end_ > 0) {
+ native_pc_offset_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ dex_pc_ = DecodeUnsignedLeb128(&encoded_table_ptr_);
+ }
} else {
DCHECK_EQ(table_->PcToDexSize(), element);
}