Re: CVS update: php3/functions
| From: | Zeev Suraski | Date: | Mon, 28 Dec 1998 22:35:06 +0000 |
| Subject: | Re: CVS update: php3/functions | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-3147@lists.php.net to get a copy of this message | ||
At 21:11 28/12/98 +0100, Sascha Schumann wrote:
>On Mon, 28 Dec 1998, Zeev Suraski wrote:
>
>> Unless I'm missing something, I'm against this patch. The optimizations
>> seem to be trivial enough for any optimizing compiler to do them by itself;
>> The real problem is that it seems to change the behavior of the function
>> altogether (an empty element is returned for a NULL field, instead of that
>> element being unset).
>
>Yes, you are missing something :-)
>
>The old code was
>
> element = PQgetvalue(pgsql_result,row->value.lval,i);
> element_len = (element ? strlen(element) : 0);
> element = safe_estrndup(element,element_len);
>
>safe_estrndup is defined as
>
>#define safe_estrndup(ptr,len) \
> ((ptr)?(estrndup((ptr),(len))):(empty_string))
>
>So if PQgetvalue() returns NULL, safe_estrndup() will return empty_string
>which results in
>
>if(element) {
> /* always being executed */
>} else {
> /* something commented out */
>}
Ok, you did find a bug then, but the fix doesn't really fix anything.
There's no reason to duplicate empty_string, ever, it can be returned as-is
as it would never be freed by any part of the PHP engine.
Zeev
--
Zeev Suraski <zeev@zend.com>
For a PGP public key, finger bourbon@netvision.net.il
--
PHP Development Mailing List http://www.php.net/
To unsubscribe send an empty message to php-dev-unsubscribe@lists.php.net
For help: php-dev-help@lists.php.net