Skip to main content
Code Review

Return to Revisions

2 of 2
Commonmark migration

Buffer overflow

There are two problems with your current attempt to prevent buffer overflow:

 if (i > ARRSIZE) printArray(reverse(buff, i), i);

The first is that your code is off by one, and if i is larger than ARRSIZE you have already overflowed your buffer by one character. So you should change > to >=. The second is that once you detect the overflow, you don't set i back to zero. So you will continue to write past the end of your buffer.

JS1
  • 28.9k
  • 3
  • 41
  • 83
default

AltStyle によって変換されたページ (->オリジナル) /