Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

typecast_array.c tests size_t against <0

#120

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

Reported by Psycopg website · August 17th, 2012 @ 11:47 AM

State: resolved
Milestone: none
Assigned to: Federico Di Gregorio Federico Di Gregorio

Activity

  1. Federico Di Gregorio
    Federico Di Gregorio
    • 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.

    August 17th, 2012 @ 11:58 AM

  2. Federico Di Gregorio
    Federico Di Gregorio
    • 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.

    August 17th, 2012 @ 12:55 PM