In DMCC.c, the function getNumberOfBytes() allocates num bytes to result, but reads num + 1 bytes (i goes from 0 to num):
char *result = (char *)malloc(sizeof(char)*num);
...
// Get bytes at the given address
int i = 0;
while(i <= num) {
result[i] = (char)(getByte(fd, addr+i));
i++;
}
This should be corrected to:
while(i < num) {
Also, if result is intended to be treated as a NULL-terminated string, and the cape does not include a NULL character at the end, then result should be allocated num + 1 bytes and a NULL should be explicitly appended.
In DMCC.c, the function
getNumberOfBytes()
allocatesnum
bytes toresult
, but readsnum + 1
bytes (i
goes from0
tonum
):This should be corrected to:
Also, if
result
is intended to be treated as a NULL-terminated string, and the cape does not include a NULL character at the end, thenresult
should be allocatednum + 1
bytes and a NULL should be explicitly appended.