bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#19154: [PATCH] Extend file size support in paste.


From: Pádraig Brady
Subject: bug#19154: [PATCH] Extend file size support in paste.
Date: Sun, 23 Nov 2014 20:12:38 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

On 23/11/14 18:50, Tobias Stoeckmann wrote:
> The function paste_parallel just has to remember if there was a character
> in a line at all, not how many.  Changing size_t to a simple boolean
> statement removes a possible overflow situation with 4 GB files on 32 bit
> systems.
> ---
>  src/paste.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/paste.c b/src/paste.c
> index 2ca75d0..630a9a6 100644
> --- a/src/paste.c
> +++ b/src/paste.c
> @@ -235,7 +235,7 @@ paste_parallel (size_t nfiles, char **fnamptr)
>          {
>            int chr IF_LINT ( = 0);    /* Input character. */
>            int err IF_LINT ( = 0);    /* Input errno value.  */
> -          size_t line_length = 0;    /* Number of chars in line. */
> +          bool foundchar = false;    /* Found chars in a line. */
>  
>            if (fileptr[i])
>              {
> @@ -250,7 +250,7 @@ paste_parallel (size_t nfiles, char **fnamptr)
>  
>                while (chr != EOF)
>                  {
> -                  line_length++;
> +                  foundchar = true;
>                    if (chr == '\n')
>                      break;
>                    xputchar (chr);
> @@ -259,7 +259,7 @@ paste_parallel (size_t nfiles, char **fnamptr)
>                  }
>              }
>  
> -          if (line_length == 0)
> +          if (!foundchar)
>              {
>                /* EOF, read error, or closed file.
>                   If an EOF or error, close the file.  */
> 

Nice one. This would result in truncation of the output
iff there was a \n at position 2^32 in the file on a 32 bit system.
I'll apply that in a little while (I can't think of an efficient way to test).

Did you notice this through inspection or compiler warnings wrt integer 
overflow ?

thanks!
Pádraig.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]