...
sizeof(size_t) > sizeof(int)
Similar behavior as the case above occurs for values of {{n <= UINT_MAX}}. For values of {{n > UINT_MAX}}, the expression {{\++i}} will wrap around to zero before the condition {{i < n}} ever evaluates to false. This causes all memory within {{\[INT_MIN, INT_MAX\]}} from the beginning of the output buffer to be overwritten in an infinite loopFor values of Wiki Markup n
where 0 < n <= INT_MAX
, the loop executes n
times, as expected. For values of n > INT_MAX
, the loop executes INT_MAX + 1
times. For each iteration, i
is in the range 0 through INT_MAX
. Once i
becomes negative, the loop will stop, because a negative value for i
converts into SIZE_MAX + 1 + i
. Because sizeof(size_t) > sizeof(int)
, SIZE_MAX
is well above INT_MAX * 2
, as well as SIZE_MAX + 1 + INT_MIN
, therefore the size_t
values i
converts to are always greater than values of n
in the range INT_MAX + 1
to INT_MAX * 2
.
Compliant Solution (TR 24731-1)
...