From: John Snow Date: Wed, 25 Nov 2015 21:03:37 +0000 (-0500) Subject: util/id: fully allocate names table X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=624533e5a53e5df347e46f06408d15b9df5254f0;p=qmiga%2Fqemu.git util/id: fully allocate names table 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 Reviewed-by: Eric Blake Reviewed-by: Jeff Cody Signed-off-by: Michael Tokarev --- diff --git a/util/id.c b/util/id.c index bcc64d836f..7883fbec79 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);