diff options
author | Derek Mauro <dmauro@google.com> | 2024-05-21 19:07:45 (GMT) |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2024-05-21 19:08:38 (GMT) |
commit | 9b4993ca7d1279dec5c5d41ba327cb11a77bdc00 (patch) | |
tree | 4e6a740f7f89232bf0ec78c067d1c061d987ee49 /googletest | |
parent | c8393f8554419dc27b688c535b8fa4afb82146a4 (diff) | |
download | googletest-9b4993ca7d1279dec5c5d41ba327cb11a77bdc00.zip googletest-9b4993ca7d1279dec5c5d41ba327cb11a77bdc00.tar.gz googletest-9b4993ca7d1279dec5c5d41ba327cb11a77bdc00.tar.bz2 |
Change GoogleTest flag removal to not read beyond the end of the array
to the NULL terminator. #4532 says ASAN complains about this on some
platforms, although it is not clear if ASAN or the platform implementation
is incorrect about accessing the terminating NULL.
Fixes #4532
PiperOrigin-RevId: 635886009
Change-Id: Ibb4237055488c895b1dd09145ab979347bb9a390
Diffstat (limited to 'googletest')
-rw-r--r-- | googletest/src/gtest.cc | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index d64c18d..9a17180 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -6700,17 +6700,17 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) { } if (remove_flag) { - // Shift the remainder of the argv list left by one. Note - // that argv has (*argc + 1) elements, the last one always being - // NULL. The following loop moves the trailing NULL element as - // well. - for (int j = i; j != *argc; j++) { - argv[j] = argv[j + 1]; + // Shift the remainder of the argv list left by one. + for (int j = i + 1; j < *argc; ++j) { + argv[j - 1] = argv[j]; } // Decrements the argument count. (*argc)--; + // Terminate the array with nullptr. + argv[*argc] = nullptr; + // We also need to decrement the iterator as we just removed // an element. i--; |