Re: cvs: php4 /ext/bz2 bz2.c
| From: | Wez Furlong | Date: | Fri, 16 Aug 2002 20:34:47 +0000 |
| Subject: | Re: cvs: php4 /ext/bz2 bz2.c | ||
| References: | 1 | Groups: | php.cvs |
| Request: | Send a blank email to php-cvs+get-13423@lists.php.net to get a copy of this message | ||
I'm not so sure that this really is a fix:
From the PR:
"bzread without a length returns a string that is not '\0' terminated.
On systems where (e)malloc returns a initialized memory it works fine,
but when the memory is not initialized it breaks.
A quick fix is to use ecalloc instead of emalloc"
bzread is returning the number of characters that were read, which
we are assigning to Z_STRLEN_P(return_value), and we use that length
to manually terminate the string.
Using calloc here just wastes CPU time zeroing the memory that we
overwrite with the read call.
I think his suggestion for calloc applies to the non-streams code
in the 4.2 branch.
--Wez.
On 08/16/02, "Dan Kalowsky" <dank@deadmime.org> wrote:
> Fix for bug #18947 submitted by pgr75@hotmail.com
> - Z_STRVAL_P(return_value) = emalloc(len + 1);
> + Z_STRVAL_P(return_value) = ecalloc(len + 1);
> Z_STRLEN_P(return_value) = php_stream_read(stream, Z_STRVAL_P(return_value), len);
> Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0;