So I have a program
#include "main.h"
#import <limits.h>
#import <stdint.h>
int foo(const void *src, void *dst, uint16_t len)
{
uint16_t index;
const uint8_t *srcRef = src;
uint8_t *dstRef = dst;
for(index = 0; index <= len; index++)
{
dstRef[index] = srcRef[index];
printf("-> %d - %d\n", index, srcRef[index]);
}
printf("%d\n", index);
return 0;
}
int main()
{
printf("max length of UInt16 is : %d\n", UINT16_MAX);
uint8_t arrOr[55];
uint8_t arr[55];
arrOr[54] = 7;
uint16_t len = 119;
foo(arrOr, arr, len);
return 0;
}
Is it normal for a program to be able to access an array index out out bounds? (I was actually expecting it to crash) It can access up to 119(120 crashes it) when array length is 55.
When it's 56, I can still only access up to 119 and 120 crashes it
When it's 57, I can access up to 135 and 136 crashes it.
I guess it's trying to access memory addresses given to the whole program and not just the array indexes. But what's actually happening when I change the array length to 57, that lets me access more addresses that I can't do by increasing it to 56?