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 <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 <egg...@cs.ucla.edu> 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