[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <7147904f-f135-5abd-c8b5-ff2cc4f0de0a@gmail.com>
Date: Fri, 11 Sep 2020 10:08:27 +0200
From: "Michael Kerrisk (man-pages)" <mtk.manpages@...il.com>
To: Alejandro Colomar <colomar.6.4.3@...il.com>
Cc: mtk.manpages@...il.com, linux-man@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 18/24] core.5: Use adequate type
On 9/10/20 11:13 PM, Alejandro Colomar wrote:
> '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@...il.com>
Thanks, Alex. Patch Applied.
Cheers,
Michael
> ---
> man5/core.5 | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/man5/core.5 b/man5/core.5
> index a87ebbaf4..45c9de845 100644
> --- a/man5/core.5
> +++ b/man5/core.5
> @@ -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);
>
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
Powered by blists - more mailing lists