]> Savannah Git Hosting - gnulib.git/commitdiff
fix freadptr to work with ungetc on all uClibc configs
authorPádraig Brady <P@draigBrady.com>
Tue, 8 Dec 2015 15:30:56 +0000 (15:30 +0000)
committerPádraig Brady <P@draigBrady.com>
Tue, 8 Dec 2015 15:38:57 +0000 (15:38 +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
lib/freadptr.c

index fffa98a3069c3ddd532b30f1bc9b7b93f89be92b..13f49662b35ee1199d43ed52415e1f85f35de1bb 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2015-12-08  Pádraig Brady  <P@draigBrady.com>
+
+       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  <eggert@cs.ucla.edu>
 
        xalloc-oversized: improve performance with GCC 5
index 818c7ee607c39294a3eb0c53c9c5b82372b31d23..3b66cd2c5ddbe33eeced1c6f3bbd6c356d10235e 100644 (file)
@@ -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;