[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [BUG] 216 Alerts reported by LGTM for QEMU (some might
Re: [Qemu-devel] [BUG] 216 Alerts reported by LGTM for QEMU (some might be release critical)
Mon, 15 Jul 2019 07:10:32 +0200
Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)
Stefan Weil <address@hidden> writes:
> Am 14.07.2019 um 19:30 schrieb Peter Maydell:
>> "Analyzer thinks this multiply can overflow
>> but in fact it's not possible" is quite a common false
>> positive cause...
> The analysers don't complain because a multiply can overflow.
> They complain because the code indicates that a larger result is
> expected, for example uint64_t = uint32_t * uint32_t. They would not
> complain for the same multiplication if it were assigned to a uint32_t.
I agree this is an anti-pattern.
> So there is a simple solution to write the code in a way which avoids
> false positives...
You wrote elsewhere in this thread:
Either the assigned value should use the same data type as the
factors (possible when there is never an overflow, avoids a size
extension), or the multiplication could use the larger data type by
adding a type cast to one of the factors (then an overflow cannot
happen, static code analysers and human reviewers have an easier
job, but the multiplication costs more time).
Makes sense to me.