flagcapper/GoogleAI-Ants-Starter-Pack — Issue #2: Invalid memory writes
Author: erjiang
Created: 2011-11-06 03:45:54+00:00
State: open

At MyBot.c:109

char *data = malloc(initial_buffer);
memset(data, 0, initial_buffer);

*data = '\n';

char *ins_data = data + 1;

int i = 0;

while (1 > 0) {
++i;

if (i > initial_buffer) {
initial_buffer *= 2;
data = realloc(data, initial_buffer);
memset(ins_data, 0, initial_buffer/2);
}

*ins_data = getchar();

You realloc data but you never update ins_data to point to the new data! If it ever outgrows its initial buffer, it will probably keep writing memory it shouldn't be writing to. Also, since `data` is only realloc'd when i is strictly greater than `initial_buffer`, it will write past the end of the buffer by one byte.