]> git.proxmox.com Git - mirror_qemu.git/commitdiff
util/id: fully allocate names table
authorJohn Snow <jsnow@redhat.com>
Wed, 25 Nov 2015 21:03:37 +0000 (16:03 -0500)
committerMichael Tokarev <mjt@tls.msk.ru>
Fri, 4 Dec 2015 06:39:55 +0000 (09:39 +0300)
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.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
util/id.c

index bcc64d836f436b72dd8e35eafc1b027e53dd63a8..7883fbec794b5186203b3b8ea519b60c781537ad 100644 (file)
--- 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);