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
This commit is contained in:
parent
c8393f8554
commit
9b4993ca7d
@ -6700,17 +6700,17 @@ void ParseGoogleTestFlagsOnlyImpl(int* argc, CharType** argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (remove_flag) {
|
if (remove_flag) {
|
||||||
// Shift the remainder of the argv list left by one. Note
|
// Shift the remainder of the argv list left by one.
|
||||||
// that argv has (*argc + 1) elements, the last one always being
|
for (int j = i + 1; j < *argc; ++j) {
|
||||||
// NULL. The following loop moves the trailing NULL element as
|
argv[j - 1] = argv[j];
|
||||||
// well.
|
|
||||||
for (int j = i; j != *argc; j++) {
|
|
||||||
argv[j] = argv[j + 1];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrements the argument count.
|
// Decrements the argument count.
|
||||||
(*argc)--;
|
(*argc)--;
|
||||||
|
|
||||||
|
// Terminate the array with nullptr.
|
||||||
|
argv[*argc] = nullptr;
|
||||||
|
|
||||||
// We also need to decrement the iterator as we just removed
|
// We also need to decrement the iterator as we just removed
|
||||||
// an element.
|
// an element.
|
||||||
i--;
|
i--;
|
||||||
|
Loading…
Reference in New Issue
Block a user