Store public selector offsets as int32

This commit is contained in:
andrew committed 2026-11-18 11:28:47 -05:00
1 parent c8e49aead8
commit 24f28dd9c8
10 files changed
+247 -227

No files matched your search

+21 -20
View File
@@ -9,6 +9,7 @@
#include <cstdint>
#include <cstdio>
#include <limits>
#include <type_traits>
#include <utility>
#include <vector>
@@ -33,33 +34,33 @@ int main() {
owned.push_back(OptKey{Key("a")});
owned.push_back(OptKey{Key("\xff\xff", 2)});
// The public offset contract accepts exactly the 32-bit boundaries; the
// entry-point assertions and corpus parsers share this predicate.
const RangeRead boundary{Selector{std::nullopt, kMinInputOffset},
Selector{std::nullopt, kMaxInputOffset}, false};
const RangeRead outside{Selector{std::nullopt, kMinInputOffset - 1},
Selector{std::nullopt, 0}, false};
if (!inputOffsetsFitInt32(boundary) || inputOffsetsFitInt32(outside)) {
// `Selector` stores offsets as `std::int32_t`, so `RangeRead` itself cannot
// violate the input contract. The corpus parsers still validate wider
// parsed values with `offsetsFitInt32` before narrowing.
static_assert(std::is_same_v<decltype(Selector::offset), std::int32_t>,
"Selector::offset must match the 32-bit input contract");
if (!offsetsFitInt32(kMinInputOffset, kMaxInputOffset) ||
offsetsFitInt32(kMinInputOffset - 1, kMaxInputOffset + 1)) {
std::fprintf(stderr, "offset contract check failed\n");
return 1;
}
const Int offs[] = {std::numeric_limits<std::int32_t>::min(),
std::numeric_limits<std::int32_t>::min() + 1,
-1000000000,
-3,
-1,
0,
1,
2,
3,
1000000000,
std::numeric_limits<std::int32_t>::max() - 1,
std::numeric_limits<std::int32_t>::max()};
const std::int32_t offs[] = {std::numeric_limits<std::int32_t>::min(),
std::numeric_limits<std::int32_t>::min() + 1,
-1000000000,
-3,
-1,
0,
1,
2,
3,
1000000000,
std::numeric_limits<std::int32_t>::max() - 1,
std::numeric_limits<std::int32_t>::max()};
std::vector<Selector> sels;
sels.reserve(owned.size() * (sizeof(offs) / sizeof(offs[0])));
for (const OptKey& k : owned)
for (Int off : offs) sels.push_back(Selector{optView(k), off});
for (std::int32_t off : offs) sels.push_back(Selector{optView(k), off});
long long cases = 0, bad = 0;
for (const Selector& bs : sels)