Received: from eggs.gnu.org ([2001:4830:134:3::10]:37409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1WaB-0005rX-Ub for qemu-devel@nongnu.org; Wed, 25 Nov 2015 04:41:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1Wa6-0007Px-Si for qemu-devel@nongnu.org; Wed, 25 Nov 2015 04:41:47 -0500 Date: Wed, 25 Nov 2015 10:41:40 +0100 From: Kevin Wolf Message-ID: <20151125094140.GC5957@noname.str.redhat.com> References: <1448407631-9405-1-git-send-email-jsnow@redhat.com> <871tbeijay.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <871tbeijay.fsf@blackfin.pond.sub.org> 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: Markus Armbruster Cc: qemu-trivial@nongnu.org, jcody@redhat.com, John Snow , qemu-devel@nongnu.org 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. Kevin