Do we have an example that demonstrates non-deterministic failures due to the incorrect malloc size in C?
For example, in my 'gzip' program in linux:
.
.
.
char* a = (char*)malloc(256) // correct version
is changed to
char* a = (char*)malloc(206) //faulty version
.
.
.
Because of this, a test case tc that pass on the correct version becomes fail (i.e., segmentation fault) on the faulty version. However, the failure is non-deterministic. Sometimes, the failed test case tc on the faulty version does not cause segmentation fault (i.e., pass).
This may be due to the 'undefined' behavior of malloc, but I could not know how it happens exactly.
Does anyone can give me some concrete example? Thank you in advance.