You might argue that you're never going to overflow a size_t on a 64-bit, maybe, but given that the correct code is right there above in the article, it seems easy enough to just do the right thing (add half the delta to the lower bound, which avoids overflow all together for unsigned integer inputs).
The input is an array of int, ints are 4 bytes, 32 bit systems can only address 2^32 bytes, so the array is no more than 2^30 elements long, so in the worst case, low+high equals 2^31-3, less than even a signed it.
It could overflow if we pass it a char* instead but if you have a >2GB array of sorted single bytes, you probably have a problem somewhere else...
I'm not sure if you've misunderstood this (some of the other comments mentioning type certainly have) but size_t being large enough for the purpose of indexing an array is absolutely not the issue. The issue, illustrated by the glibc code pishpash shared, is that a size_t (or any other integer type) is not necessarily large enough to hold the sum of two other variables of the same type without overflowing.
#include <stdio.h>
#include <stdint.h>
int main() {
printf("size_t bytes: %u\n", sizeof(size_t));
size_t high = SIZE_MAX;
size_t low = high-1;
size_t mid_correct = low+(high-low)/2;
size_t mid_incorrect = (low+high)/2;
printf("low: %.ju\n", low);
printf("high: %.ju\n", high);
printf("low+high: %.ju\n", low+high);
printf("(low+high)/2 -- incorrect: %.ju\n", mid_incorrect);
printf("low+(high-low)/2 -- correct: %.ju\n", mid_correct);
}
On my 64-bit machine, I get: size_t bytes: 8
low: 18446744073709551614
high: 18446744073709551615
low+high: 18446744073709551613
(low+high)/2 -- incorrect: 9223372036854775806
low+(high-low)/2 -- correct: 18446744073709551614The unsigned types are generally awful; they have a big discontinuity right at zero, so you have to be careful with arithmetic even if it involves small values.
If I'm working with int and I know that all quantities fit into two decimal digits, then there isn't possibly any problem. Not so with unsigned int or size_t or what have you.
If a, b, c are small integers in a signed type then I know I can rewrite a < b + c as a - c < b, following straight algebraic rules of derivation. Not so if these are unsigned; moving c from the right side to the left may break the inequality because a may be smaller than c.
Of course sorting 2^63 elements would require the different calculation.
y = a[0]*y[-1] + a[1]*y[-2] + b[0]*x[-1] + b[1]*x[-2]