poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Possible undefined behavior in IOS


From: Jose E. Marchesi
Subject: Possible undefined behavior in IOS
Date: Sat, 01 May 2021 19:40:32 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hi Egeyar.

GCC -fanalyzer reported the following warnings:

7326:../../libpoke/ios.c:700:35: warning: shift by count ('64') >= precision of 
type ('64')
7382:../../libpoke/ios.c:1478:19: warning: shift by count ('64') >= precision 
of type ('64')

These reference code in ios.c like this:

        /* We should shift to fill the least significant byte
        which is the last 8 bits.  */
        *value = ((uint64_t) c[0] << (56 + lastbyte_bits))
                 | ((uint64_t) c[1] << (48 + lastbyte_bits))
                 | ((uint64_t) c[2] << (40 + lastbyte_bits))
                 | ((uint64_t) c[3] << (32 + lastbyte_bits))
                 | ((uint64_t) c[4] << (24 + lastbyte_bits))
                 | ((uint64_t) c[5] << (16 + lastbyte_bits))
                 | (c[6] << (8 + lastbyte_bits)) | (c[7] << lastbyte_bits)
                 | (c[8] >> (8 - lastbyte_bits));

Note how the code above incurs in UB when lastbyte_bits >= 8.  I suppose
that this is a false positive and that in these two particular locations
lastbyte_bits can't be 8, but it would be good to double-check it.

Could you please take a look?
Thanks!



reply via email to

[Prev in Thread] Current Thread [Next in Thread]