Skip to main content
Code Review

Return to Answer

Commonmark migration
Source Link

###Buffer overflow###

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.

###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.

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.

Source Link
JS1
  • 28.8k
  • 3
  • 41
  • 83

###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.

lang-c

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