chiark / gitweb /
collect: realloc buffer, if needed
authorXinwei Hu <hxinwei@gmail.com>
Tue, 27 May 2008 17:35:03 +0000 (19:35 +0200)
committerKay Sievers <kay.sievers@vrfy.org>
Tue, 27 May 2008 17:35:03 +0000 (19:35 +0200)
extras/collect/collect.c

index 0a852f2..feb0e75 100644 (file)
@@ -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));
                }
        }