]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
core/tools: Protect result of ARRAY_SIZE
authorJan Kiszka <jan.kiszka@siemens.com>
Thu, 6 Nov 2014 16:00:10 +0000 (17:00 +0100)
committerJan Kiszka <jan.kiszka@siemens.com>
Thu, 6 Nov 2014 16:00:10 +0000 (17:00 +0100)
Prevent any operator prioritization issues when embedding ARRAY_SIZE
into an expression by protecting the result with braces. This is a
defensive measure, no current user was affected by it.

Do not convert all the generated or copy&pasted ARRAY_SIZE defines in
the config files as long as they are not affected by the issue.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
hypervisor/include/jailhouse/utils.h
tools/root-cell-config.c.tmpl

index 15c7b296ec2bf9e641df8b8ad9a5bf85eddf8c78..e319efd90dd2770d066e3ae4202309b79364bf5e 100644 (file)
@@ -10,7 +10,7 @@
  * the COPYING file in the top-level directory.
  */
 
-#define ARRAY_SIZE(array)      sizeof(array) / sizeof((array)[0])
+#define ARRAY_SIZE(array)      (sizeof(array) / sizeof((array)[0]))
 
 /* create 64-bit mask with bytes 0 to size-1 set to 0xff */
 #define BYTE_MASK(size)                (0xffffffffffffffffULL >> ((8 - (size)) * 8))
index 2a57a5a7f26debce7e7e85617a1340b0ed95fa97..fa314df8d8c0ae0dd0ff4cedac13fba1cb23c143 100644 (file)
@@ -16,7 +16,7 @@
 #include <linux/types.h>
 #include <jailhouse/cell-config.h>
 
-#define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0])
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
 struct {
        struct jailhouse_system header;