Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6da17b47 authored by Greg Kaiser's avatar Greg Kaiser
Browse files

Avoid null dereference crash in test failure

We can't use ASSERT in these non-void functions, but we want to
stop executing them when our vector is empty.  Otherwise, we'll
crash with a null dereference and further confuse debugging for
users.

Bug: 362510140
Test: Local 'atest VtsHalVibratorTargetTest', while it still fails a couple tests, no longer segfaults.
Flag: EXEMPT for testing bug fix
Change-Id: I2deb674f0b13b0b511177fb95cc6fdc3160c49bc
parent a7aa1242
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -120,6 +120,11 @@ static float getPwleV2FrequencyMinHz(const std::shared_ptr<IVibrator>& vibrator)
    EXPECT_OK(
            vibrator->getPwleV2FrequencyToOutputAccelerationMap(&frequencyToOutputAccelerationMap));
    EXPECT_TRUE(!frequencyToOutputAccelerationMap.empty());
    // We can't use ASSERT_TRUE() above because this is a non-void function,
    // but we need to return to assure we don't crash from a null dereference.
    if (frequencyToOutputAccelerationMap.empty()) {
        return std::numeric_limits<float>::quiet_NaN();
    }

    auto entry = std::min_element(
            frequencyToOutputAccelerationMap.begin(), frequencyToOutputAccelerationMap.end(),
@@ -133,6 +138,11 @@ static float getPwleV2FrequencyMaxHz(const std::shared_ptr<IVibrator>& vibrator)
    EXPECT_OK(
            vibrator->getPwleV2FrequencyToOutputAccelerationMap(&frequencyToOutputAccelerationMap));
    EXPECT_TRUE(!frequencyToOutputAccelerationMap.empty());
    // We can't use ASSERT_TRUE() above because this is a non-void function,
    // but we need to return to assure we don't crash from a null dereference.
    if (frequencyToOutputAccelerationMap.empty()) {
        return std::numeric_limits<float>::quiet_NaN();
    }

    auto entry = std::max_element(
            frequencyToOutputAccelerationMap.begin(), frequencyToOutputAccelerationMap.end(),