gcc – Interpreting valgrind error Invalid write of size 4

gcc – Interpreting valgrind error Invalid write of size 4

points_read is most likely out of bounds, youre writing past (or before) the memory you allocated for amplitudes.

A typical mistake new programmers do to get this warning is:

struct a *many_a;
many_a = malloc(sizeof *many_a * size + 1);

and then try to read or write to the memory at location size:

many_a[size] = ...;

Here the allocation should be:

many_a = malloc(sizeof *many_a * (size + 1));

gcc – Interpreting valgrind error Invalid write of size 4

Leave a Reply

Your email address will not be published. Required fields are marked *