]> granicus.if.org Git - php/commitdiff
Fixed bug #45585 (fread() return value for EOF inconsistent
authorArnaud Le Blanc <lbarnaud@php.net>
Tue, 11 Nov 2008 00:40:05 +0000 (00:40 +0000)
committerArnaud Le Blanc <lbarnaud@php.net>
Tue, 11 Nov 2008 00:40:05 +0000 (00:40 +0000)
between PHP 5 and 6)

ext/standard/file.c
ext/standard/tests/file/bug45585.phpt [new file with mode: 0644]

index 0d91456fc2d142ccd5c371549e013ca2ee4aef7e..90ad47f32d2547c15d70fb05a2c444deebf0f626 100644 (file)
@@ -1984,19 +1984,11 @@ PHPAPI PHP_FUNCTION(fread)
                int buflen = len;
                UChar *buf = php_stream_read_unicode_chars(stream, &buflen);
 
-               if (!buf) {
-                       RETURN_FALSE;
-               }
-
                RETURN_UNICODEL(buf, buflen, 0);
        } else { /* IS_STRING */
                char *buf = emalloc(len + 1);
                int buflen = php_stream_read(stream, buf, len);
 
-               if (!buflen) {
-                       efree(buf);
-                       RETURN_FALSE;
-               }
                buf[buflen] = 0;
                RETURN_STRINGL(buf, buflen, 0);
        }
diff --git a/ext/standard/tests/file/bug45585.phpt b/ext/standard/tests/file/bug45585.phpt
new file mode 100644 (file)
index 0000000..3e7cda1
--- /dev/null
@@ -0,0 +1,14 @@
+--TEST--
+Bug #45585 (fread() return value for EOF inconsistent between PHP 5 and 6)
+--FILE--
+<?php
+$fd = fopen("php://temp","w+");
+fwrite($fd, b"foo");
+fseek($fd, 0, SEEK_SET);
+var_dump($fd, fread($fd, 3), fread($fd, 3));
+fclose($fd);
+?>
+--EXPECTF--
+resource(%d) of type (stream)
+string(3) "foo"
+string(0) ""