qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: qemu-trivial@nongnu.org, jcody@redhat.com,
	John Snow <jsnow@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [trivial for-2.6] util/id: fully allocate names table
Date: Wed, 25 Nov 2015 11:27:24 +0100	[thread overview]
Message-ID: <87vb8qcr1v.fsf@blackfin.pond.sub.org> (raw)
In-Reply-To: <20151125094140.GC5957@noname.str.redhat.com> (Kevin Wolf's message of "Wed, 25 Nov 2015 10:41:40 +0100")

Kevin Wolf <kwolf@redhat.com> writes:

> Am 25.11.2015 um 09:18 hat Markus Armbruster geschrieben:
>> John Snow <jsnow@redhat.com> writes:
>> 
>> > Trivial: this array should be allocated to have ID_MAX entries always.
>> > Otherwise if someone were to forget to expand this table, the assertion
>> > in the id generator won't actually trigger; it will read junk data.
>> 
>> You mean this one:
>> 
>>     assert(id < ID_MAX);
>> 
>> The assertion is crap, because it fails to protect array access
>> id_subsys_str[id].  Here's one that does:
>> 
>>     assert(0 <= id && id < ARRAY_SIZE(id_subsys_str));
>
> Or without the kraxelism id >= 0. However, depending on whether enums
> are signed or unsigned, I seem to remember that this could trigger
> compiler warnings (comparison is always true). And this one should be
> unsigned with gcc because it doesn't include negative values.

Whatever it takes to express the range check in a way the compiler
likes.

Since ARRAY_SIZE()'s value is size_t, and size_t is unsigned, the
comparison with 0 can simply be omitted.

  reply	other threads:[~2015-11-25 10:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-24 23:27 [Qemu-devel] [trivial for-2.6] util/id: fully allocate names table John Snow
2015-11-25  8:18 ` Markus Armbruster
2015-11-25  9:41   ` Kevin Wolf
2015-11-25 10:27     ` Markus Armbruster [this message]
2015-11-25 15:17   ` John Snow

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=87vb8qcr1v.fsf@blackfin.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=jcody@redhat.com \
    --cc=jsnow@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).