[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] libbb: Fix xmalloc_fgets() newline handling
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2018-09-03 14:03:40
Message-ID: CAK1hOcM+4wkLnMtgDYEXR0BWc7gwZVcTdSZTKHw4rzwYhM4bxw () mail ! gmail ! com
[Download RAW message or body]

Applied, thanks
On Fri, Aug 31, 2018 at 2:06 PM Mark Thompson
<mark.thompson@starleaf.com> wrote:
> 
> Since 2da9724b56169f00bd7fb6b9a11c9409a7620981, xmalloc_fgets() will always
> return the entirety of a text file rather than stopping at '\n' as one would
> expect from fgets().  This is visible in for example 'head -n -1', which
> outputs nothing rather than all but the last line of the input.
> 
> Signed-off-by: Mark Thompson <mark.thompson@starleaf.com>
> ---
> Found from tracking down why 'ifdown foo' would always protest that 'foo' was \
> unconfigured, despite it being in the ifstate file (but not as the first line).  \
> The 'head -n -1' example is a much easier way to show the problem, and there are \
> probably a few other places with unexpected behaviour because of it. 
> 
> libbb/get_line_from_file.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libbb/get_line_from_file.c b/libbb/get_line_from_file.c
> index f3d6c62..ad04e3a 100644
> --- a/libbb/get_line_from_file.c
> +++ b/libbb/get_line_from_file.c
> @@ -47,7 +47,8 @@ char* FAST_FUNC bb_get_chunk_from_file(FILE *file, size_t *end)
> /* Get line, including trailing \n if any */
> char* FAST_FUNC xmalloc_fgets(FILE *file)
> {
> -       return bb_get_chunk_from_file(file, NULL);
> +       size_t i;
> +       return bb_get_chunk_from_file(file, &i);
> }
> /* Get line.  Remove trailing \n */
> char* FAST_FUNC xmalloc_fgetline(FILE *file)
> --
> 2.7.4
> _______________________________________________
> busybox mailing list
> busybox@busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic