Use realloc instead of manually reallocating

This commit is contained in:
Axel Wagner 2010-09-17 02:28:56 +02:00
parent a702ced322
commit d245d14765
1 changed files with 1 additions and 5 deletions

View File

@ -61,12 +61,8 @@ void stdin_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
} }
if (n == 0) { if (n == 0) {
if (rec == buffer_len) { if (rec == buffer_len) {
char *tmp = buffer;
buffer = malloc(buffer_len + STDIN_CHUNK_SIZE);
memset(buffer, '\0', buffer_len);
strncpy(buffer, tmp, buffer_len);
buffer_len += STDIN_CHUNK_SIZE; buffer_len += STDIN_CHUNK_SIZE;
FREE(tmp); buffer = realloc(buffer, buffer_len);
} else { } else {
/* remove trailing newline and finish up */ /* remove trailing newline and finish up */
buffer[rec-1] = '\0'; buffer[rec-1] = '\0';