bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] fix freadptr to work with ungetc on all uClibc configs


From: Pádraig Brady
Subject: [PATCH] fix freadptr to work with ungetc on all uClibc configs
Date: Tue, 8 Dec 2015 15:39:17 +0000

This was noticed at https://bugs.busybox.net/show_bug.cgi?id=4099
where GNU coreutils cut fails like:

  $echo '3:0:0:' | cut -d : -f 2
  30

The reason is because GNU cut uses ungetc(),
and that wasn't handled appropriately on uClibc
when __UCLIBC_HAS_STDIO_GETC_MACRO__ is not defined.

* lib/freadptr.c (freadptr): Return NULL if there are
ungotten chars.  In this case freadseek() will iterate
again to process the ungotten character.
---
 ChangeLog      | 10 ++++++++++
 lib/freadptr.c |  2 ++
 2 files changed, 12 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index fffa98a..13f4966 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2015-12-08  P??draig Brady  <address@hidden>
+
+       fix freadptr to work with ungetc on all uClibc configs
+       Reported at https://bugs.busybox.net/show_bug.cgi?id=4099
+       where GNU coreutils cut(1) generates invalid output on uClibc
+       when __UCLIBC_HAS_STDIO_GETC_MACRO__ is not defined.
+       * lib/freadptr.c (freadptr): Return NULL if there are
+       ungotten chars.  In this case freadseek() will iterate
+       again to process the ungotten character.
+
 2015-11-13  Paul Eggert  <address@hidden>
 
        xalloc-oversized: improve performance with GCC 5
diff --git a/lib/freadptr.c b/lib/freadptr.c
index 818c7ee..3b66cd2 100644
--- a/lib/freadptr.c
+++ b/lib/freadptr.c
@@ -77,6 +77,8 @@ freadptr (FILE *fp, size_t *sizep)
 # ifdef __STDIO_BUFFERS
   if (fp->__modeflags & __FLAG_WRITING)
     return NULL;
+  if (fp->__modeflags & __FLAG_UNGOT)
+    return NULL;
   size = fp->__bufread - fp->__bufpos;
   if (size == 0)
     return NULL;
-- 
2.5.0




reply via email to

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