Hi,
The issue seems to be in the way you read the file into memory in the read_file function. You are reading parts of the file into memory that has not been allocated.
I'd suggest you read the file in small chunks in a loop, using "realloc" to make the buffer a bit larger on each iteration of the loop and then filling that newly created space as it is created.
In pseudocode:
// open file, initialize buffer
while(/*still things to read*/) {
// extend buffer with n more chars using realloc
// read n more chars to buffer (use f.ex. fread)
}
Remember to account for the null byte at all stages. You might also do the loop as a "do { ... } while ( file_did_not_end );"
Hope that gets you on the right track :)
-L