]> granicus.if.org Git - php/commitdiff
fix #36981 (SplFileObject->fgets() ignores max_length)
authorAntony Dovgal <tony2001@php.net>
Thu, 6 Apr 2006 19:01:56 +0000 (19:01 +0000)
committerAntony Dovgal <tony2001@php.net>
Thu, 6 Apr 2006 19:01:56 +0000 (19:01 +0000)
NEWS
ext/spl/spl_directory.c

diff --git a/NEWS b/NEWS
index bb7dadcd7fa06ff30142ebe03d961f5537c46a6f..b6ebcf73e0f0b4744204d8b5ce1c6e13b17fac96 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,7 @@ PHP                                                                        NEWS
 - Removed the E_STRICT deprecation notice from "var". (Ilia)
 - Fixed debug_zval_dump() to support private and protected members. (Dmitry)
 - Fixed SoapFault::getMessage(). (Dmitry)
+- Fixed bug #36981 (SplFileObject->fgets() ignores max_length). (Tony)
 - Fixed bug #36957 (serialize() does not handle recursion). (Ilia)
 - Fixed bug #36944 (strncmp & strncasecmp do not return false on negative 
   string length). (Tony)
index 4fb7533b2abdc3904f91d4fb764b6aa5861e780a..6d5cb2250a0b84ed106093713a897bc4cea008bb 100755 (executable)
@@ -1327,7 +1327,7 @@ static zend_function_entry spl_RecursiveDirectoryIterator_functions[] = {
 static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */
 {
        char *buf;
-       size_t line_len;
+       size_t line_len = 0;
        int len;
        long line_add = (intern->u.file.current_line || intern->u.file.current_zval) ? 1 : 0;
 
@@ -1340,7 +1340,17 @@ static int spl_filesystem_file_read(spl_filesystem_object *intern, int silent TS
                return FAILURE;
        }
 
-       buf = php_stream_get_line(intern->u.file.stream, NULL, intern->u.file.max_line_len, &line_len);
+       if (intern->u.file.max_line_len > 0) {
+               buf = emalloc((intern->u.file.max_line_len + 1) * sizeof(char));
+               if (php_stream_get_line(intern->u.file.stream, buf, intern->u.file.max_line_len, &line_len) == NULL) {
+                       efree(buf);
+                       buf = NULL;
+               } else {
+                       buf[line_len] = '\0';
+               }
+       } else {
+               buf = php_stream_get_line(intern->u.file.stream, NULL, 0, &line_len);
+       }
 
        if (!buf) {
                intern->u.file.current_line = estrdup("");