chiark / gitweb /
collect: fix size_t printf
[elogind.git] / extras / collect / collect.c
index feb0e7576871551e6e5984c32a0e43d51a79b9dc..ce49b9f410c5630ea6ce70898ab456042b4aa806 100644 (file)
@@ -53,7 +53,7 @@ static LIST_HEAD(bunch);
 static int debug;
 
 /* This can increase dynamically */
-static int bufsize = BUFSIZE;
+static size_t bufsize = BUFSIZE;
 
 static void sig_alrm(int signo)
 {
@@ -147,7 +147,7 @@ static int checkout(int fd)
                        if (!ptr && word < (buf + len)) {
                                bufsize = bufsize << 1;
                                if (debug)
-                                       fprintf(stderr, "ID overflow, restarting with size %d\n", bufsize);
+                                       fprintf(stderr, "ID overflow, restarting with size %zi\n", bufsize);
                                free(buf);
                                lseek(fd, 0, SEEK_SET);
                                goto restart;
@@ -272,8 +272,15 @@ static int missing(int fd)
                        ret++;
                } else {
                        while (strlen(him->name)+1 >= bufsize) {
+                               char *tmpbuf;
+
                                bufsize = bufsize << 1;
-                               buf = realloc(buf, bufsize);
+                               tmpbuf = realloc(buf, bufsize);
+                               if (!tmpbuf) {
+                                       free(buf);
+                                       return -1;
+                               }
+                               buf = tmpbuf;
                        }
                        snprintf(buf, strlen(him->name)+2, "%s ", him->name);
                        write(fd, buf, strlen(buf));