c99-snprintf icon indicating copy to clipboard operation
c99-snprintf copied to clipboard

Static analysis: Overflowed return value

Open tbeu opened this issue 8 years ago • 1 comments

Coverity Scan reports an Overflowed return value from function myround.

static UINTMAX_T
myround(LDOUBLE value)
{
    UINTMAX_T intpart = cast(value);

//1. Condition (value -= intpart) < 0.5, taking false branch.
//2. overflow: Add operation overflows on operands intpart and 1UL.
//CID 59973 (#1 of 1): Overflowed return value (INTEGER_OVERFLOW)
//3. overflow_sink: Overflowed or truncated value (or a value computed from an overflowed or truncated value) ((value -= intpart) < 0.5) ? intpart : (intpart + 1UL) used as return value.
    return ((value -= intpart) < 0.5) ? intpart : intpart + 1;
}

tbeu avatar Nov 22 '16 09:11 tbeu

The call to cast() can return UINTMAX_MAX, in which case the return statement will overflow.

zfields avatar Dec 14 '21 21:12 zfields