On Thu, Jul 03, 2014 at 07:51:19PM +0200, Toralf Förster via RT wrote:
> the latest git tree fro yesterday + the latest git tree of cppcheck yields
> into these warning :
>
>
> The 2 "if"s seems to be superfluous, or ? :
>
The code before that is:
/* convert integer part */
do {
iconvert[iplace++] =
(caps ? "0123456789ABCDEF"
: "0123456789abcdef")[intpart % 10];
intpart = (intpart / 10);
} while (intpart && (iplace < (int)sizeof(iconvert)));
> if (iplace == sizeof iconvert)
> iplace--;
> iconvert[iplace] = 0;<--- Array 'iconvert[20]' accessed at index 20,
> which is out of bounds. Otherwise condition 'iplace==20' is redundant.
The comment is wrong. iplace can be sizeof(iconvert) when the
while loop is left, and in that case is decreased with 1. So
it's now max 19, and that if is not redundant.
> /* convert fractional part */
> do {
> fconvert[fplace++] =
> (caps ? "0123456789ABCDEF"
> : "0123456789abcdef")[fracpart % 10];
> fracpart = (fracpart / 10);
> } while (fplace < max);
> if (fplace == sizeof fconvert)
> fplace--;
> fconvert[fplace] = 0;<--- Array 'fconvert[20]' accessed at index 20,
> which is out of bounds. Otherwise condition 'fplace==20' is redundant.
In this case "max" is maximum 9. So fplace can be up to 10 which
is smaller than the 20. So the if could be removed here since you
can't actually get there. But I think the while should actually
be changed to also check the sizeof fconvert in case someone
thinks it's a good idea to change max.
Kurt
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List [email protected]
Automated List Manager [email protected]