heap corruption detected
The program writes to memory in a way that corrupts the heap or stack, often leading to crashes or unpredictable behavior.
int main() {
int *arr = malloc(5 * sizeof(int));
arr[10] = 42; // Writing beyond allocated memory
free(arr);
return 0;
}Ensure all memory accesses are within allocated bounds and initialize pointers before use.
int main() {
int *arr = malloc(5 * sizeof(int));
if (arr != NULL) {
for (int i = 0; i < 5; i++) {
arr[i] = i; // Stay within bounds
}
free(arr);
}
return 0;
}