Skip to content

Commit e148a52

Browse files
committed
bench: fixed ubsan implicit conversion
The benchmarks can now run much longer due to the minimum of 10ms or directly with -min_time. With -min_time=20000 I could trigger two ubsan errors in the benchmarks, which are fixed in this commit by using unsigned type and adding "& 0xFF".
1 parent da4e2f1 commit e148a52

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/bench/crypto_hash.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ static void MuHash(benchmark::Bench& bench)
110110
{
111111
MuHash3072 acc;
112112
unsigned char key[32] = {0};
113-
int i = 0;
113+
uint32_t i = 0;
114114
bench.run([&] {
115-
key[0] = ++i;
115+
key[0] = ++i & 0xFF;
116116
acc *= MuHash3072(key);
117117
});
118118
}

src/bench/rollingbloom.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ static void RollingBloom(benchmark::Bench& bench)
1313
uint32_t count = 0;
1414
bench.run([&] {
1515
count++;
16-
data[0] = count;
17-
data[1] = count >> 8;
18-
data[2] = count >> 16;
19-
data[3] = count >> 24;
16+
data[0] = count & 0xFF;
17+
data[1] = (count >> 8) & 0xFF;
18+
data[2] = (count >> 16) & 0xFF;
19+
data[3] = (count >> 24) & 0xFF;
2020
filter.insert(data);
2121

22-
data[0] = count >> 24;
23-
data[1] = count >> 16;
24-
data[2] = count >> 8;
25-
data[3] = count;
22+
data[0] = (count >> 24) & 0xFF;
23+
data[1] = (count >> 16) & 0xFF;
24+
data[2] = (count >> 8) & 0xFF;
25+
data[3] = count & 0xFF;
2626
filter.contains(data);
2727
});
2828
}

0 commit comments

Comments
 (0)