mirror of
https://github.com/ETLCPP/etl.git
synced 2026-07-30 16:26:17 +08:00
Fix etl::pearson::reset() not resetting the first-byte flag (#1487)
reset() cleared the hash array but left the `first` flag false, so a calculator reused after reset() took the XOR update path on its next add() instead of the initialisation path. This produced an incorrect hash for any pearson object that was reset and reused. Reset `first` to true in reset() so a reset calculator behaves like a freshly constructed one. Add test_pearson_reset regression test. Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
This commit is contained in:
parent
032ec4cc80
commit
165674cb23
@ -93,6 +93,7 @@ namespace etl
|
|||||||
void reset()
|
void reset()
|
||||||
{
|
{
|
||||||
hash.fill(0);
|
hash.fill(0);
|
||||||
|
first = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
|
|||||||
@ -144,6 +144,25 @@ namespace
|
|||||||
CHECK(compare == hash);
|
CHECK(compare == hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//*************************************************************************
|
||||||
|
TEST(test_pearson_reset)
|
||||||
|
{
|
||||||
|
std::string data("123456789");
|
||||||
|
|
||||||
|
etl::pearson<HASH_SIZE> pearson_calculator;
|
||||||
|
|
||||||
|
// Use the calculator, then reset it and reuse it for the same data.
|
||||||
|
pearson_calculator.add(data.begin(), data.end());
|
||||||
|
pearson_calculator.reset();
|
||||||
|
pearson_calculator.add(data.begin(), data.end());
|
||||||
|
|
||||||
|
hash_t compare = Pearson_Compare(data);
|
||||||
|
hash_t hash = pearson_calculator.value();
|
||||||
|
|
||||||
|
// A reset calculator must produce the same hash as a fresh one.
|
||||||
|
CHECK(compare == hash);
|
||||||
|
}
|
||||||
|
|
||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
TEST(test_pearson_add_range_endian)
|
TEST(test_pearson_add_range_endian)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user