This project is archived and is in readonly mode.
typecast_array.c tests size_t against <0
Reported by Psycopg website | August 17th, 2012 @ 11:47 AM
Submitted by: mjl@laubach.at
The clang compiler complains that:
In file included from psycopg/typecast.c:179:
./psycopg/typecast_array.c:227:31: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (--stack_index < 0)
~~~~~~~~~~~~~ ^ ~
1 warning generated.
and indeed, it is right, size_t is unsigned, so this is never true.
if(stack_index-- <= 0)
should do the trick.
Cheers,
mjl
Comments and changes to this ticket
-
Federico Di Gregorio August 17th, 2012 @ 11:58 AM
- State changed from new to open
The warning is correct but using <= instead of < would break array parsing. That test is a guard to avoid the (impossible?) case of receiving more ASCAN_END than ASCAN_BEGIN from the tokenizer. IMO, that guard can be removed.
-
Federico Di Gregorio August 17th, 2012 @ 12:55 PM
- State changed from open to resolved
- Assigned user set to Federico Di Gregorio
This is better:
if (stack_index == 0) return -1; array = stack[--stack_index];
and should fix the warning.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="https://github.com/psycopg/psycopg2/issues">the new tracker</a>.
<br/>
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.