3 ms·
There is a way for this not to terminate: while (new_capacity < required) { new_capacity *= 2; } 1. All variables are unsigned (due to being size_t).
by kazinator 1y ago
There is a way for this not to terminate:
while (new_capacity < required) {
new_capacity *= 2;
}
1. All variables are unsigned (due to being size_t). So we don't worry about overflow UB.
2. new_capacity * 2 always produces an even number, whether truncating or not.
3. Supppose required is SIZE_MAX, the highest value of size_t; note that this is an odd number.
4. Therefore new_capacity * 2 is always < required; loop does not terminate.