# size_t, casting and expression is always true (or false)

- Thread: https://externals.io/message/51417
- Original archive: https://news-web.php.net/php.internals/51417
- Started by Richard Quadling on 2011-02-01T13:35:26+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #51417 — Richard Quadling — 2011-02-01T13:35:26+00:00

URL: https://externals.io/message/51417#51417

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

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

-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

---

## #51418 — Richard Quadling — 2011-02-01T15:15:00+00:00

URL: https://externals.io/message/51417#51418

>  Hi Richard,
> 
> > […]
>
> which mysqlnd/PHP sources did you use in your build?
>
> > […]
>
> 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
