From: Xinwei Hu Date: Tue, 27 May 2008 17:35:03 +0000 (+0200) Subject: collect: realloc buffer, if needed X-Git-Tag: 174~1690 X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b5254b42032b39e393f5c89102ca71c2b3fa0d11;p=systemd collect: realloc buffer, if needed --- diff --git a/extras/collect/collect.c b/extras/collect/collect.c index 0a852f2d..feb0e757 100644 --- a/extras/collect/collect.c +++ b/extras/collect/collect.c @@ -271,7 +271,11 @@ static int missing(int fd) if (him->state == STATE_NONE) { ret++; } else { - sprintf(buf, "%s ", him->name); + while (strlen(him->name)+1 >= bufsize) { + bufsize = bufsize << 1; + buf = realloc(buf, bufsize); + } + snprintf(buf, strlen(him->name)+2, "%s ", him->name); write(fd, buf, strlen(buf)); } }