Fix RealDataBench subspan and version API contract violations
CI / release (arm64, ubuntu-latest-arm64) (pull_request) Successful in 3m33s
CI / pre-commit (pull_request) Successful in 2m4s
CI / test (-DCMAKE_BUILD_TYPE=Debug, debug) (pull_request) Successful in 3m38s
CI / test (-DCMAKE_CXX_FLAGS=-DUSE_64_BIT=1, 64-bit-versions) (pull_request) Successful in 3m29s
CI / test (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc) (pull_request) Successful in 3m38s
CI / test (-DUSE_SIMD_FALLBACK=ON, simd-fallback) (pull_request) Successful in 3m30s
CI / release (amd64, ubuntu-latest-amd64) (pull_request) Successful in 4m57s
CI / coverage (pull_request) Successful in 3m40s

- Use subspan count `line.size() - 2` instead of `line.size()` to avoid reading past the line bounds, and guard lines shorter than the two-byte prefix.
- Clamp `readVersion` and `setOldestVersion` arguments to `0` so the conflict set never receives negative, non-monotonic versions during the warmup phase.

Fixes #58.
This commit is contained in:
2026-06-29 14:01:23 -04:00
parent 8f9f345c64
commit 4fcdc5d7e9
+7 -6
View File
@@ -1,5 +1,6 @@
#include <ConflictSet.h> #include <ConflictSet.h>
#include <algorithm>
#include <cerrno> #include <cerrno>
#include <chrono> #include <chrono>
#include <cstdio> #include <cstdio>
@@ -77,10 +78,10 @@ int main(int argc, const char **argv) {
begin = end + 1; begin = end + 1;
end = (uint8_t *)memchr(begin, '\n', size); end = (uint8_t *)memchr(begin, '\n', size);
if (line.size() > 0 && line[0] == 'P') { if (line.size() >= 2 && line[0] == 'P') {
write = line.subspan(2, line.size()); write = line.subspan(2, line.size() - 2);
} else if (line.size() > 0 && line[0] == 'L') { } else if (line.size() >= 2 && line[0] == 'L') {
reads.push_back(line.subspan(2, line.size())); reads.push_back(line.subspan(2, line.size() - 2));
} else if (line.empty()) { } else if (line.empty()) {
{ {
readRanges.resize(reads.size()); readRanges.resize(reads.size());
@@ -90,7 +91,7 @@ int main(int argc, const char **argv) {
iter->begin.len = read.size(); iter->begin.len = read.size();
checkBytes += read.size(); checkBytes += read.size();
iter->end.len = 0; iter->end.len = 0;
iter->readVersion = version - 100; iter->readVersion = std::max<int64_t>(0, version - 100);
++iter; ++iter;
} }
} }
@@ -121,7 +122,7 @@ int main(int argc, const char **argv) {
} }
timer = now(); timer = now();
cs.setOldestVersion(version - 10000); cs.setOldestVersion(std::max<int64_t>(0, version - 10000));
gcTime += now() - timer; gcTime += now() - timer;
} }
} }