#5086·googletest

[Bug]: Empty integer flag values are silently parsed as zero

Author: MuszicCreated Sep 3, 2026Updated Sep 3, 2026

Describe the issue

Empty values for integer GoogleTest flags are silently accepted as zero instead of being rejected as invalid integers.

For example, --gtest_repeat= sets the repeat count to zero. The test program then executes no test iterations, prints no warning or help, and exits successfully. This can turn a malformed test command into a false-green test run.

testing::internal::ParseInt32 uses strtol and checks only whether unconsumed characters remain. For an empty string, strtol consumes no digits, returns zero, and leaves end == str. Since *end is also the terminating NUL, the current check treats the conversion as successful.

I expect an empty value to be rejected in the same way as any other string that does not contain a decimal integer. An explicit value of zero, such as --gtest_repeat=0, should remain valid.

Steps to reproduce the problem

Configure and build the repository tests:

cmake -S . -B build -Dgtest_build_tests=ON -Dgmock_build_tests=ON
cmake --build build --parallel 4

Run a test binary with an empty repeat value:

./build/googletest/gtest_main_unittest \
  --gtest_repeat= \
  --gtest_fail_if_no_test_selected \
  --gtest_color=no
echo $?

Observed output:

Running main() from googletest/src/gtest_main.cc
0

No test is executed and no diagnostic is printed. As a control, replacing the empty value with abc produces the expected invalid-integer warning and help output.

The same parser is used by the other integer flags, including random seed, stack trace depth, shard index/total, and GoogleMock's default mock behavior.

What version of GoogleTest are you using?

Current main at efbef50b594e3f6f3fdeb77b9b4e1ab34e4d1e0f.

What operating system and version are you using?

macOS 26.6.2 (Build 25G83), Apple Silicon.

What compiler and version are you using?

Apple clang 21.0.0 (clang-2100.1.1.101), target arm64-apple-darwin25.6.0.

What build system are you using?

CMake 4.4.3.

Additional context

The missing validation is in googletest/src/gtest-port.cc: after calling strtol, the parser should also verify that at least one character was consumed (end != str).

A focused regression can call ParseInt32 with an empty string and verify that it returns false without changing the destination value. Some existing invalid-value ParseFlag tests use --abc=... rather than the required --gtest_abc=..., so they currently return before reaching ParseInt32; correcting those prefixes would make that coverage effective as well.