Received: from eggs.gnu.org ([2001:4830:134:3::10]:33833) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1hE7-00041q-7G for qemu-devel@nongnu.org; Wed, 25 Nov 2015 16:03:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1hE4-0003Gt-26 for qemu-devel@nongnu.org; Wed, 25 Nov 2015 16:03:43 -0500 From: John Snow Date: Wed, 25 Nov 2015 16:03:37 -0500 Message-Id: <1448485417-8196-1-git-send-email-jsnow@redhat.com> Subject: [Qemu-devel] [PATCH v2] util/id: fully allocate names table List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-trivial@nongnu.org, jcody@redhat.com, John Snow 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. v2: Fix the range assertion, too. Compare against the known actual size of the table instead of what it "should" be. Signed-off-by: John Snow --- util/id.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util/id.c b/util/id.c index bcc64d8..7883fbe 100644 --- a/util/id.c +++ b/util/id.c @@ -29,7 +29,7 @@ bool id_wellformed(const char *id) #define ID_SPECIAL_CHAR '#' -static const char *const id_subsys_str[] = { +static const char *const id_subsys_str[ID_MAX] = { [ID_QDEV] = "qdev", [ID_BLOCK] = "block", }; @@ -53,7 +53,7 @@ char *id_generate(IdSubSystems id) static uint64_t id_counters[ID_MAX]; uint32_t rnd; - assert(id < ID_MAX); + assert(id < ARRAY_SIZE(id_subsys_str)); assert(id_subsys_str[id]); rnd = g_random_int_range(0, 100); -- 2.4.3