oops. my fault. lack of attention, as usual.
you had
Code:
result[ires-1]++;
which does not overflow the array.
my apologies.