https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83407

--- Comment #7 from Jonny Grant <jg at jguk dot org> ---
As the compiler knows size_t returned by vec.size() is unsigned, it could warn
that the code should have a sanity check as it is size_t.  It is the same when
code checks for UINT_MAX to avoid similar issues...


ie, rather than:

printf("vec size minus header: %zu\n", vec.size() -1);

gcc warning:  vec.size() returns unsigned type which is not checked for
unsigned wraparound


have:

// vec.size() is a size_t type
if(vec.size() >= 1)
{
    printf("vec size minus header: %zu\n", vec.size() -1);
}
else
{
    printf("vec empty\n");
}

Reply via email to