From: Markus Armbruster <armbru@redhat.com>
To: Stefan Weil <sw@weilnetz.de>
Cc: Kevin Wolf <kwolf@redhat.com>,
Peter Maydell <peter.maydell@linaro.org>,
Eduardo Habkost <ehabkost@redhat.com>,
QEMU Developers <qemu-devel@nongnu.org>,
Max Reitz <mreitz@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Richard Henderson <rth@twiddle.net>
Subject: Re: [Qemu-devel] [BUG] 216 Alerts reported by LGTM for QEMU (some might be release critical)
Date: Mon, 15 Jul 2019 07:10:32 +0200 [thread overview]
Message-ID: <87tvbnzxvb.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <63d96e86-3823-2586-eb25-44beff91f8f2@weilnetz.de> (Stefan Weil's message of "Sun, 14 Jul 2019 19:44:55 +0200")
Stefan Weil <sw@weilnetz.de> 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.
next prev parent reply other threads:[~2019-07-15 5:10 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-13 17:46 [Qemu-devel] [BUG] 216 Alerts reported by LGTM for QEMU (some might be release critical) Stefan Weil
2019-07-13 19:42 ` Paolo Bonzini
2019-07-14 13:28 ` Stefan Weil
2019-07-15 8:26 ` Kevin Wolf
2019-07-14 17:30 ` Peter Maydell
2019-07-14 17:44 ` Stefan Weil
2019-07-15 5:10 ` Markus Armbruster [this message]
2019-07-15 8:08 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tvbnzxvb.fsf@dusky.pond.sub.org \
--to=armbru@redhat.com \
--cc=ehabkost@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.