Avoid UB in CodeItemDebugInfoAccessor::Init
Bug: http://b/219526286
Initialize `dex_file_` even if `code_item` is nullptr. Later in
`elf_debug_writer.h:WriteCompilationUnit`, the call to
`DecodeDebugPositionInfo` assumes that `dex_file_` is initialized.
Test: Revert aosp/1984608 and the following passes:
SOONG_ALLOW_MISSING_DEPENDENCIES=true HOST_PREFER_32_BIT=true m -j32 test-art-host-gtest-art_oatdump_tests32
Change-Id: Ie8b9adf25742a6c2448dfbbc201155b7933ef3d3
diff --git a/libdexfile/dex/code_item_accessors-inl.h b/libdexfile/dex/code_item_accessors-inl.h
index 261b913..1e33002 100644
--- a/libdexfile/dex/code_item_accessors-inl.h
+++ b/libdexfile/dex/code_item_accessors-inl.h
@@ -187,10 +187,10 @@
inline void CodeItemDebugInfoAccessor::Init(const DexFile& dex_file,
const dex::CodeItem* code_item,
uint32_t dex_method_index) {
+ dex_file_ = &dex_file;
if (code_item == nullptr) {
return;
}
- dex_file_ = &dex_file;
if (dex_file.IsCompactDexFile()) {
Init(down_cast<const CompactDexFile::CodeItem&>(*code_item), dex_method_index);
} else {