[BUG] Large iteration counts are parsed incorrectly on Windows
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 src/benchmark_runner.cc 中的 ParseBenchMinTime() 开始,issue 指出 std::strtol 是 Windows 上溢出的原因。检查现有的后缀和错误处理,然后查看所描述的回归测试,涵盖 32 位边界值、更大的计数、有符号 64 位整数的最大值以及拒绝溢出。完成的标准是解析器返回预期的 64 位计数并拒绝溢出。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
On Windows x64, --benchmark_min_time=4294967296x requests
4,294,967,296 iterations, but the Release build parses the count
as 2,147,483,647.
System
- Windows x64
- MSVC 19.44
- Upstream commit: 48ece68f18fff770e873d398d58bd27afe15ea7e
- Release build configured with CMake
To reproduce
Call benchmark::internal::ParseBenchMinTime("4294967296x")
and inspect the returned iters field.
- Expected: 4294967296
- Actual on Windows Release: 2147483647
The reproduction calls the parser directly; it does not execute
billions of benchmark iterations.
Observed output
Input Expected Actual
2147483647x 2147483647 2147483647
2147483648x 2147483648 2147483647
4294967296x 4294967296 2147483647
1000000000000x 1000000000000 2147483647
Cause And Proposed Fix
ParseBenchMinTime() in src/benchmark_runner.cc uses
std::strtol, whose return type is a 32-bit long on Windows,
although IterationCount is 64-bit.
For these larger values, the conversion overflows before the
result is assigned to IterationCount. The existing BM_CHECK
is disabled in Release builds, so the saturated value is returned.
I have prepared a fix using std::strtoll, preserving the existing
suffix and error checks, together with regression tests for the
32-bit boundary, larger counts, the maximum signed 64-bit count,
and overflow rejection.
Would this change be welcome?
Validation
- The new regression fails before the fix and passes afterward.
- All 88 Windows Release CTest tests pass with the fix.
- All three focused Debug min-time tests pass, including overflow checks.
- Linux and Bazel builds have not been tested locally.
AI Disclosure
AI tools assisted with investigating and reproducing this bug,
preparing the proposed fix and tests, running validation, and
drafting this report.
- 主要语言
- C++
- 星标
- 10.5k
- 派生
- 1.8k
- 平均合并
- 2 天 1 小时
- 30 天内合并 PR
- 28
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
google/benchmark 的其他 Issue
-
[BUG] Memory manager counts allocations not part of benchmark可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
google/benchmark#2149 · 7 条评论 ·
维护者通常 1 天内回复
-
[FR] New "benchstat" output format可能已有人在做 @DenysZm 于 4 天前认领。 未关闭
google/benchmark#2397 · 4 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 45/100
google/benchmark#2391 · 1 条评论 ·
维护者通常 1 天内回复
-
[FR] Add native Zig bindings via top-level `bindings/zig`可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 5/5 一周以上 新手友好度 42/100
google/benchmark#2266 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
google/benchmark#2235 · 2 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
component: tabs platform: macOS
难度 2/5 1-3 小时 新手友好度 72/100
zen-browser/desktop#16860 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 88/100
metasequoiaime/msime#12003 ·
维护者通常 1 天内回复