Received: from eggs.gnu.org ([2001:4830:134:3::10]:46437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1XIS-00086j-Ol for qemu-devel@nongnu.org; Wed, 25 Nov 2015 05:27:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1XIN-00022r-Jb for qemu-devel@nongnu.org; Wed, 25 Nov 2015 05:27:32 -0500 From: Markus Armbruster References: <1448407631-9405-1-git-send-email-jsnow@redhat.com> <871tbeijay.fsf@blackfin.pond.sub.org> <20151125094140.GC5957@noname.str.redhat.com> Date: Wed, 25 Nov 2015 11:27:24 +0100 In-Reply-To: <20151125094140.GC5957@noname.str.redhat.com> (Kevin Wolf's message of "Wed, 25 Nov 2015 10:41:40 +0100") Message-ID: <87vb8qcr1v.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [trivial for-2.6] util/id: fully allocate names table List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf Cc: qemu-trivial@nongnu.org, jcody@redhat.com, John Snow , qemu-devel@nongnu.org Kevin Wolf writes: > Am 25.11.2015 um 09:18 hat Markus Armbruster geschrieben: >> John Snow 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.