In C, I noticed I can write to static array off-limits, for example:
static char a[10] = {0};
for (int i=0; i<20; i++) {
a[i] = 'a'; // Should fail when i > 9
}
I expected to get segmentation fault but it executes just fine.
If static arrays were allocated on the stack, it would make sense, but they're not, so why is that so?
Note: static int arrays behave similarly. Didn't check other types.
Thanks.
Edit: This is not a duplicate since the other questions were not about static arrays. Unlike "regular" arrays, static arrays are allocated in BSS. The behavior might be different, which is why I'm asking separately.