fix #36981 (SplFileObject->fgets() ignores max_length)

This commit is contained in:
Antony Dovgal 2006-04-06 19:01:56 +00:00
parent 8f7319a49f
commit ad7768ee63
2 changed files with 13 additions and 2 deletions

1
NEWS
View File

@ -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)

View File

@ -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("");