diff --git a/e2e_tests/functional_test.cc b/e2e_tests/functional_test.cc index 3ba3f739..497c6b1c 100644 --- a/e2e_tests/functional_test.cc +++ b/e2e_tests/functional_test.cc @@ -1378,6 +1378,13 @@ TEST_P(FuzzingModeCrashFindingTest, DivByZeroTestFindsAbortInFuzzingMode) { #endif } +TEST_P(FuzzingModeCrashFindingTest, Int32ValueTestFindsAbortInFuzzingMode) { + auto [status, std_out, std_err] = Run("MySuite.Int32ValueTest"); + // -559038737 is 0xdeadbeef in int32_t. + EXPECT_THAT(std_err, HasSubstr("argument 0: -559038737")); + ExpectTargetAbort(status, std_err); +} + TEST_P(FuzzingModeCrashFindingTest, CoverageTestFindsAbortInFuzzingMode) { auto [status, std_out, std_err] = Run("MySuite.Coverage"); EXPECT_THAT(std_err, HasSubstr("argument 0: 'F'")); diff --git a/fuzztest/internal/centipede_adaptor.cc b/fuzztest/internal/centipede_adaptor.cc index 02689808..894129d0 100644 --- a/fuzztest/internal/centipede_adaptor.cc +++ b/fuzztest/internal/centipede_adaptor.cc @@ -236,6 +236,19 @@ class CentipedeAdaptorRunnerCallbacks : public centipede::RunnerCallbacks { } private: + template + static void InsertCmpEntryIntoIntegerDictionary(const uint8_t* a, + const uint8_t* b) { + T a_int; + T b_int; + memcpy(&a_int, a, sizeof(T)); + memcpy(&b_int, b, sizeof(T)); + GetExecutionCoverage() + ->GetTablesOfRecentCompares() + .GetMutable() + .Insert(a_int, b_int); + } + void SetMetadata(const centipede::ExecutionMetadata* metadata) { if (metadata == nullptr) return; metadata->ForEachCmpEntry([](centipede::ByteSpan a, centipede::ByteSpan b) { @@ -244,8 +257,13 @@ class CentipedeAdaptorRunnerCallbacks : public centipede::RunnerCallbacks { const size_t size = a.size(); if (size < kMinCmpEntrySize) return; if (size > kMaxCmpEntrySize) return; - // TODO(xinhaoyuan): Consider handling integer comparison and - // memcmp entries differently. + if (size == 2) { + InsertCmpEntryIntoIntegerDictionary(a.data(), b.data()); + } else if (size == 4) { + InsertCmpEntryIntoIntegerDictionary(a.data(), b.data()); + } else if (size == 8) { + InsertCmpEntryIntoIntegerDictionary(a.data(), b.data()); + } GetExecutionCoverage() ->GetTablesOfRecentCompares() .GetMutable<0>()