]> granicus.if.org Git - php/commitdiff
- Fix issue in _php_stream_get_line(): Allow maxchars == 0 as macro
authorMarcus Boerger <helly@php.net>
Sat, 18 Mar 2006 19:44:51 +0000 (19:44 +0000)
committerMarcus Boerger <helly@php.net>
Sat, 18 Mar 2006 19:44:51 +0000 (19:44 +0000)
  php_stream_get_line() does

main/streams/streams.c

index 79ea5a05f8246bae6beed5eb83b3c45651d63d2b..5f7431a5ae2541466d7a58c6ec1c08983db39dfa 100755 (executable)
@@ -1053,20 +1053,22 @@ PHPAPI void *_php_stream_get_line(php_stream *stream, int buf_type, zstr buf, si
                        }
 
                        if (is_unicode) {
-                               int ulen = u_countChar32(readptr.u, cpysz);
-
-                               if (ulen > maxchars) {
-                                       int32_t i = 0;
-
-                                       ulen = maxchars;
-                                       U16_FWD_N(readptr.u, i, cpysz, ulen);
-                                       cpysz = i;
+                               if (maxchars) {
+                                       int ulen = u_countChar32(readptr.u, cpysz);
+       
+                                       if (ulen > maxchars) {
+                                               int32_t i = 0;
+       
+                                               ulen = maxchars;
+                                               U16_FWD_N(readptr.u, i, cpysz, ulen);
+                                               cpysz = i;
+                                       }
+                                       maxchars -= ulen;
                                }
-                               maxchars -= ulen;
                                memcpy(buf.u, readptr.u, UBYTES(cpysz));
                                buf.u += cpysz;
                        } else {
-                               if (cpysz > maxchars) {
+                               if (maxchars && cpysz > maxchars) {
                                        cpysz = maxchars;
                                }
                                memcpy(buf.s, readptr.s, cpysz);
@@ -1105,10 +1107,12 @@ PHPAPI void *_php_stream_get_line(php_stream *stream, int buf_type, zstr buf, si
                }
        }
 
+       if (returned_len) {
+               *returned_len = total_copied;
+       }
+
        if (total_copied == 0) {
-               if (grow_mode) {
-                       assert(bufstart.v == NULL);
-               }
+               assert(bufstart.v != NULL || !grow_mode || stream->eof);
                return NULL;
        }