[BUG] Large iteration counts are parsed incorrectly on Windows

未关闭 适合新手
#2,406 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cmake, cpp
领域
backend, testing

调研方向

从 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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

google/benchmark 的其他 Issue

查看 google/benchmark 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。