]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
core.5: Use adequate type
authorAlejandro Colomar <colomar.6.4.3@gmail.com>
Thu, 10 Sep 2020 21:13:39 +0000 (23:13 +0200)
committerMichael Kerrisk <mtk.manpages@gmail.com>
Fri, 11 Sep 2020 09:33:28 +0000 (11:33 +0200)
'nread' is of type 'ssize_t'
'tot' adds up different values contained in 'nread',
so it should also be 'ssize_t', and not 'int' (which possibly overflows).

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
man5/core.5

index a87ebbaf4609aace96cd955024a77de372017de6..45c9de8459facea7c2ad9ed296331d0be9f167dc 100644 (file)
@@ -654,8 +654,7 @@ Total bytes in core dump: 282624
 int
 main(int argc, char *argv[])
 {
-    int tot;
-    ssize_t nread;
+    ssize_t nread, tot;
     char buf[BUF_SIZE];
     FILE *fp;
     char cwd[PATH_MAX];
@@ -684,7 +683,7 @@ main(int argc, char *argv[])
     tot = 0;
     while ((nread = read(STDIN_FILENO, buf, BUF_SIZE)) > 0)
         tot += nread;
-    fprintf(fp, "Total bytes in core dump: %d\en", tot);
+    fprintf(fp, "Total bytes in core dump: %zd\en", tot);
 
     fclose(fp);
     exit(EXIT_SUCCESS);