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