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

Re: [Minios-devel] [UNIKRAFT/LIBNEWLIB PATCH 1/1] Fix fwrite's return value for newline ended strings



Hi Vlad,

Looks good, thanks. You might want to get in touch with the newlib maintainers 
regarding this.

-- Felipe

Reviewed-by: Felipe Huici <felipe.huici@xxxxxxxxx>

============================================================
Dr. Felipe Huici
Chief Researcher, Systems and Machine Learning Group
NEC Laboratories Europe GmbH
Kurfuerstenanlage 36, D-69115 Heidelberg
Tel.  +49
(0)6221 4342-241
Fax:  +49
(0)6221 4342-155
 
e-mail:
felipe.huici@xxxxxxxxx
============================================================
Registered at Amtsgericht Mannheim, Germany, HRB728558

On 10.04.19, 13:22, "Vlad-Andrei BĂDOIU (78692)" 
<vlad_andrei.badoiu@xxxxxxxxxxxxxxx> wrote:

    Fwrite does not return the correct number of items
    written. If we pass a string that ends in '\n' we
    get n - 1(the '\n') for a string of length n.
    That is because __sputc_r returns EOF for the
    the newline character. This patch solves the problem
    by increasing the variable i if  __sputc_r returned
    EOF when p[i] is '\n'.
    
    Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
    ---
     patches/0002-Fixed-fwrite.patch | 39 +++++++++++++++++++++++++++++++++
     1 file changed, 39 insertions(+)
     create mode 100644 patches/0002-Fixed-fwrite.patch
    
    diff --git a/patches/0002-Fixed-fwrite.patch 
b/patches/0002-Fixed-fwrite.patch
    new file mode 100644
    index 0000000..2be388c
    --- /dev/null
    +++ b/patches/0002-Fixed-fwrite.patch
    @@ -0,0 +1,39 @@
    +From c83670abf70a04ed21c567e659ab66136b40796f Mon Sep 17 00:00:00 2001
    +From: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
    +Date: Wed, 10 Apr 2019 13:09:41 +0300
    +Subject: [PATCH 1/1] Fix fwrite
    +
    +Fwrite does not return the correct number of items 
    +written. If we pass a string that ends in '\n' we
    +get n - 1(the '\n') for a string of length n.
    +That is because __sputc_r returns EOF for the 
    +the newline character. This patch solves the problem 
    +by increasing the variable i if  __sputc_r returned 
    +EOF when p[i] is '\n'.
    +
    +Signed-off-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
    +---
    + newlib/libc/stdio/fwrite.c | 7 +++++--
    + 1 file changed, 5 insertions(+), 2 deletions(-)
    +
    +diff --git a/newlib/libc/stdio/fwrite.c b/newlib/libc/stdio/fwrite.c
    +index 6b3ff90..d910247 100644
    +--- a/newlib/libc/stdio/fwrite.c
    ++++ b/newlib/libc/stdio/fwrite.c
    +@@ -188,8 +188,11 @@ _DEFUN(_fwrite_r, (ptr, buf, size, count, fp),
    + 
    +   while (i < n)
    +     {
    +-      if (__sputc_r (ptr, p[i], fp) == EOF)
    +-  break;
    ++      if (__sputc_r (ptr, p[i], fp) == EOF) {
    ++          if (p[i] == '\n')
    ++                  i++;
    ++          break;
    ++    }
    + 
    +       i++;
    +     }
    +-- 
    +2.20.1
    +
    -- 
    2.20.1
    
    

_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.