]> granicus.if.org Git - php/commitdiff
MFH:
authorFelipe Pena <felipe@php.net>
Thu, 30 Oct 2008 14:36:34 +0000 (14:36 +0000)
committerFelipe Pena <felipe@php.net>
Thu, 30 Oct 2008 14:36:34 +0000 (14:36 +0000)
- Fix the fix
- Improved test

ext/standard/streamsfuncs.c
ext/standard/tests/streams/bug46426.phpt

index 4a7644d3c37c8711bf1ea99bed2f1b05075c5961..d84cfc538ca35f98e6e9fc03a54f0409111f11d4 100644 (file)
@@ -406,7 +406,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 || (pos == 0 && ZEND_NUM_ARGS() > 2)) && 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;
        }
index 05bc9c1e3cd56040e5565ff0223a3195231a31b6..8c95ea456e527d76c2b381c5894b733403f5fd25 100644 (file)
@@ -7,16 +7,28 @@ $tmp = tmpfile();
 
 fwrite($tmp, "12345");
 
-echo stream_get_contents($tmp, -1, 0);
+echo stream_get_contents($tmp, 2, 1);
+echo "\n";
+echo stream_get_contents($tmp, -1);
 echo "\n";
-echo stream_get_contents($tmp, -1, 1);
+echo stream_get_contents($tmp, -1, 0);
 echo "\n";
 echo stream_get_contents($tmp, -1, 2);
+echo "\n";
+echo stream_get_contents($tmp, 0, 0);
+echo "\n";
+echo stream_get_contents($tmp, 1, 0);
+echo "\n";
+echo stream_get_contents($tmp, -1);
 
 @unlink($tmp);
 
 ?>
 --EXPECT--
+23
+45
 12345
-2345
 345
+
+1
+2345