Re: size_t, casting and expression is always true (or false)
| From: | Richard Quadling | Date: | Tue, 01 Feb 2011 15:15:00 +0000 |
| Subject: | Re: size_t, casting and expression is always true (or false) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-51418@lists.php.net to get a copy of this message | ||
On 1 February 2011 15:07, Andrey Hristov <php@hristov.com> wrote:
> Hi Richard,
> On 02/01/2011 02:35 PM, Richard Quadling wrote:
>> Hi.
>>
>> I was looking at the cause for a test failing.
>>
>> It came down to ...
>>
>> size_t n;
>>
>> if (n < 0) {
>> // Code never reached as n is unsigned and cannot be negative.
>> }
>>
>>
>> I'm not a strong c developer, but from reading it seems that size_t is
>> always unsigned.
>>
>> Using the windows compiler (and turning on all the warnings via /Wall
>> though /W4 should be enough), this warning reports as ...
>>
>> xxx\yyy.c(nnn) : warning C4296: '>=' : expression is always false
>>
>> I then ran a full build and extracted all the C4926 warnings.
>>
>> main\network.c(1175) : warning C4296: '>=' : expression is always true
>> main\streams\filter.c(363) : warning C4296: '<' : expression is always false
>> main\streams\streams.c(921) : warning C4296: '>=' : expression is always true
>> ext\mysqlnd\mysqlnd.c(1006) : warning C4296: '>=' : expression is always true
>> ext\mysqlnd\mysqlnd.c(1031) : warning C4296: '>=' : expression is always true
>> ext\mysqlnd\mysqlnd_loaddata.c(215) : warning C4296: '<' : expression
>> is always false
>> ext\mysqlnd\mysqlnd_loaddata.c(223) : warning C4296: '<' : expression
>> is always false
>> ext\mysqlnd\mysqlnd_ps.c(1480) : warning C4296: '<' : expression is always
>> false
>> ext\mysqlnd\mysqlnd_ps.c(1620) : warning C4296: '<' : expression is always
>> false
>> ext\standard\ftp_fopen_wrapper.c(645) : warning C4296: '>=' :
>> expression is always true
>> ext\standard\image.c(645) : warning C4296: '<' : expression is always false
>> ext\standard\streamsfuncs.c(637) : warning C4296: '>=' : expression is
>> always true
>> ext\standard\streamsfuncs.c(677) : warning C4296: '>=' : expression is
>> always true
>> ext\standard\var.c(403) : warning C4296: '<' : expression is always false
>> ext\pdo\pdo_stmt.c(463) : warning C4296: '<' : expression is always false
>> ext\soap\php_encoding.c(2794) : warning C4296: '<' : expression is always
>> false
>
> which mysqlnd/PHP sources did you use in your build?
>
>> In the case of the bug [1], the incorrect type comparison resulted in
>> the suppression of an error which cased the test to fail, leading me
>> here.
>>
>> I think other comparisons in the above list are also suppressing
>> errors (I think mysqlnd will fail to report a loss of connection
>> during mysqlnd_handle_local_infile() for example).
>>
>> Regards,
>>
>> Richard.
>>
>> [1] http://bugs.php.net/bug.php?id=49072
>>
>
> Best,
> Andrey
>
php-src/branches/PHP5_3/ext/mysqlnd
I've not run the code or any tests. I was just commenting on the
parallels between bug#49072 and the code that is being reported.
Richard.
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY