[BUG] Large iteration counts are parsed incorrectly on Windows

オープン 初心者向け
#2,406 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cmake, cpp
領域
backend, testing

調査の方向性

src/benchmark_runner.cc の ParseBenchMinTime() から始めます。issue では、Windows でのオーバーフローの原因として std::strtol が挙げられています。既存のサフィックスとエラーの処理を確認し、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時間
マージ済み PR(30日)
28

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

google/benchmark のほかの issue

google/benchmark の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。