From 2029e77e183ead9a358f841f96fd8917ddbcaf22 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 6 Jan 2007 15:54:14 +0000 Subject: [PATCH] * Fix fread() issue with standard input reading. --- src/load-stream.c | 6 +++++- test/testsuite.sh | 11 +++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/load-stream.c b/src/load-stream.c index 80f53e6..00bda76 100644 --- a/src/load-stream.c +++ b/src/load-stream.c @@ -179,8 +179,12 @@ size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) if(ret >= 0) { /* XXX: the number of bytes read is not ret * size, because - * a partial read may have advanced the stream pointer */ + * a partial read may have advanced the stream pointer. However, + * when reading from a pipe ftell() will return 0, and ret * size + * is then better than nothing. */ long int newpos = ftell(stream); + if(newpos <= 0) + newpos = ret * size; if(newpos != pos) { _zz_fuzz(fd, ptr, newpos - pos); diff --git a/test/testsuite.sh b/test/testsuite.sh index 518b307..a3e3148 100755 --- a/test/testsuite.sh +++ b/test/testsuite.sh @@ -18,7 +18,7 @@ check() ZZOPTS="$1" CMD="$2" ALIAS="$3" - echo -n " $(echo "$ALIAS: " | cut -b1-15)" + echo -n " $(echo "$ALIAS .............." | cut -b1-15) " NEWMD5="$(eval "$ZZUF $ZZOPTS $CMD" 2>/dev/null | md5sum | cut -b1-32)" if [ -z "$MD5" ]; then MD5="$NEWMD5" @@ -69,15 +69,18 @@ for r in 0.000000 0.00001 0.0001 0.001 0.01 0.1 1.0 10.0; do OK=1 MD5="" check "$ZZOPTS" "cat $file" "cat" - check "$ZZOPTS" "-i cat < $file" "cat stdin" + check "$ZZOPTS" "-i cat < $file" "|cat" case $file in *text*) # We don't include grep or sed when the input is not text, because # they put a newline at the end of their input if it was not there # initially. (Linux sed doesn't, but OS X sed does.) check "$ZZOPTS" "grep -- -a '' $file" "grep -a ''" - check "$ZZOPTS" "-- sed -e n $file" "sed -e n" - #check "$ZZOPTS" "-- cut -b1- $file" "cut -b1-" + check "$ZZOPTS" "-i grep -- -a '' < $file" "|grep -a ''" + check "$ZZOPTS" "sed -- -e n $file" "sed -e n" + check "$ZZOPTS" "-i sed -- -e n < $file" "|sed -e n" + #check "$ZZOPTS" "cut -- -b1- $file" "cut -b1-" + #check "$ZZOPTS" "-i cut -- -b1- < $file" "|cut -b1-" ;; esac check "$ZZOPTS" "dd bs=65536 if=$file" "dd(bs=65536)"