]> granicus.if.org Git - php/commitdiff
- Fixed bug #46426 (3rd parameter offset of stream_get_contents not works for "0")
authorFelipe Pena <felipe@php.net>
Thu, 30 Oct 2008 10:08:01 +0000 (10:08 +0000)
committerFelipe Pena <felipe@php.net>
Thu, 30 Oct 2008 10:08:01 +0000 (10:08 +0000)
ext/standard/streamsfuncs.c
ext/standard/tests/streams/bug46426.phpt [new file with mode: 0644]

index f983a4df59bc414ef957e64e94694229c013b6ed..043fe9dc549db815a22521b189d56361e88e7b7e 100644 (file)
@@ -408,7 +408,7 @@ PHP_FUNCTION(stream_get_contents)
 
        php_stream_from_zval(stream, &zsrc);
 
-       if (pos > 0 && php_stream_seek(stream, pos, SEEK_SET) < 0) {
+       if (pos >= 0 && php_stream_seek(stream, pos, SEEK_SET) < 0) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failed to seek to position %ld in the stream", pos);
                RETURN_FALSE;
        }
diff --git a/ext/standard/tests/streams/bug46426.phpt b/ext/standard/tests/streams/bug46426.phpt
new file mode 100644 (file)
index 0000000..05bc9c1
--- /dev/null
@@ -0,0 +1,22 @@
+--TEST--
+Bug #46426 (3rd parameter offset of stream_get_contents not works for "0")
+--FILE--
+<?php
+
+$tmp = tmpfile();
+
+fwrite($tmp, "12345");
+
+echo stream_get_contents($tmp, -1, 0);
+echo "\n";
+echo stream_get_contents($tmp, -1, 1);
+echo "\n";
+echo stream_get_contents($tmp, -1, 2);
+
+@unlink($tmp);
+
+?>
+--EXPECT--
+12345
+2345
+345