diff --git a/handler/linux/exception_handler_server_test.cc b/handler/linux/exception_handler_server_test.cc index 40f06e64..e16d93b7 100644 --- a/handler/linux/exception_handler_server_test.cc +++ b/handler/linux/exception_handler_server_test.cc @@ -253,7 +253,10 @@ class ExceptionHandlerServerTest : public testing::TestWithParam { pid_t last_client; ASSERT_TRUE(server_test_->Delegate()->WaitForException( 5.0, &last_client, &last_address)); - EXPECT_EQ(last_address, info.exception_information_address); + // `exception_information_address` is underaligned and `EXPECT_EQ` + // internally takes arguments by reference. Copy it into a temporary + // before comparing to avoid undefined behavior. + EXPECT_EQ(last_address, VMAddress{info.exception_information_address}); EXPECT_EQ(last_client, ChildPID()); } else { CheckedReadFileAtEOF(ReadPipeHandle()); diff --git a/minidump/minidump_misc_info_writer_test.cc b/minidump/minidump_misc_info_writer_test.cc index 970c3338..ff132b90 100644 --- a/minidump/minidump_misc_info_writer_test.cc +++ b/minidump/minidump_misc_info_writer_test.cc @@ -178,8 +178,11 @@ void ExpectMiscInfoEqual( expected_misc_info.XStateData.SizeOfInfo); EXPECT_EQ(observed_misc_info.XStateData.ContextSize, expected_misc_info.XStateData.ContextSize); - EXPECT_EQ(observed_misc_info.XStateData.EnabledFeatures, - expected_misc_info.XStateData.EnabledFeatures); + // `EnabledFeatures` is underaligned and `EXPECT_EQ` internally takes + // arguments by reference. Copy it into a temporary before comparing to avoid + // undefined behavior. + EXPECT_EQ(uint64_t{observed_misc_info.XStateData.EnabledFeatures}, + uint64_t{expected_misc_info.XStateData.EnabledFeatures}); for (size_t feature_index = 0; feature_index < std::size(observed_misc_info.XStateData.Features); ++feature_index) { diff --git a/snapshot/minidump/process_snapshot_minidump_test.cc b/snapshot/minidump/process_snapshot_minidump_test.cc index 00fc3f84..31e304c2 100644 --- a/snapshot/minidump/process_snapshot_minidump_test.cc +++ b/snapshot/minidump/process_snapshot_minidump_test.cc @@ -868,8 +868,9 @@ TEST(ProcessSnapshotMinidump, ThreadsWithNames) { } TEST(ProcessSnapshotMinidump, System) { - const char* cpu_info = "GenuineIntel"; - const uint32_t* cpu_info_bytes = reinterpret_cast(cpu_info); + const char cpu_info[] = "GenuineIntel"; + uint32_t cpu_info_bytes[3]; + memcpy(cpu_info_bytes, cpu_info, sizeof(cpu_info_bytes)); StringFile string_file; MINIDUMP_HEADER header = {}; diff --git a/util/posix/signals_test.cc b/util/posix/signals_test.cc index de8deb22..15c44995 100644 --- a/util/posix/signals_test.cc +++ b/util/posix/signals_test.cc @@ -164,9 +164,12 @@ void CauseSignal(int sig, int code) { * Arm architecture. */ #if defined(ARCH_CPU_X86_FAMILY) - [[maybe_unused]] volatile int a = 42; - volatile int b = 0; - a = a / b; + // Dividing by zero is undefined in C, so the compiler is permitted to + // optimize out the division. Instead, divide using inline assembly. As + // this instruction will trap anyway, we skip declaring any clobbers or + // output registers. + int a = 42, b = 0; + asm volatile("idivl %2" : : "a"(0), "d"(a), "r"(b)); #endif break; }