All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: Greg Kurz <groug@kaod.org>
Subject: [PULL 5/8] fsdev/p9array.h: check scalar type in P9ARRAY_NEW()
Date: Wed, 27 Oct 2021 15:18:33 +0200	[thread overview]
Message-ID: <c0451f0bc4210d262268ff51c053a9277f20f862.1635340713.git.qemu_oss@crudebyte.com> (raw)
In-Reply-To: <cover.1635340713.git.qemu_oss@crudebyte.com>

Make sure at compile time that the scalar type of the array
requested to be created via P9ARRAY_NEW() matches the scalar
type of the passed auto reference variable (unique pointer).

Suggested-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Christian Schoenebeck <qemu_oss@crudebyte.com>
Message-Id: <c1965e2a096835dc9e1d4d659dfb15d96755cbe0.1633097129.git.qemu_oss@crudebyte.com>
---
 fsdev/p9array.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fsdev/p9array.h b/fsdev/p9array.h
index fff946a3d7..6aa25327ca 100644
--- a/fsdev/p9array.h
+++ b/fsdev/p9array.h
@@ -27,6 +27,8 @@
 #ifndef QEMU_P9ARRAY_H
 #define QEMU_P9ARRAY_H
 
+#include "qemu/compiler.h"
+
 /**
  * P9Array provides a mechanism to access arrays in common C-style (e.g. by
  * square bracket [] operator) in conjunction with reference variables that
@@ -149,6 +151,10 @@
  * @param len - amount of array elements to be allocated immediately
  */
 #define P9ARRAY_NEW(scalar_type, auto_var, len) \
+    QEMU_BUILD_BUG_MSG( \
+        !__builtin_types_compatible_p(scalar_type, typeof(*auto_var)), \
+        "P9Array scalar type mismatch" \
+    ); \
     p9array_new_##scalar_type((&auto_var), len)
 
 #endif /* QEMU_P9ARRAY_H */
-- 
2.20.1



  parent reply	other threads:[~2021-10-27 13:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-27 13:18 [PULL 0/8] 9p queue 2021-10-27 Christian Schoenebeck
2021-10-27 13:18 ` [PULL 4/8] 9pfs: introduce P9Array Christian Schoenebeck
2021-10-27 13:18 ` [PULL 2/8] 9pfs: deduplicate iounit code Christian Schoenebeck
2021-10-27 13:18 ` Christian Schoenebeck [this message]
2021-10-27 13:18 ` [PULL 7/8] 9pfs: make V9fsPath usable via P9Array API Christian Schoenebeck
2021-10-27 13:18 ` [PULL 3/8] 9pfs: simplify blksize_to_iounit() Christian Schoenebeck
2021-10-27 13:18 ` [PULL 6/8] 9pfs: make V9fsString usable via P9Array API Christian Schoenebeck
2021-10-27 13:18 ` [PULL 1/8] 9pfs: fix wrong I/O block size in Rgetattr Christian Schoenebeck
2021-10-27 13:18 ` [PULL 8/8] 9pfs: use P9Array in v9fs_walk() Christian Schoenebeck
2021-10-27 14:05 ` [PULL 0/8] 9p queue 2021-10-27 Christian Schoenebeck
2021-10-27 15:36   ` Philippe Mathieu-Daudé
2021-10-27 16:21     ` Christian Schoenebeck
2021-10-27 16:48       ` Philippe Mathieu-Daudé
2021-10-27 17:29         ` Christian Schoenebeck
2021-10-27 18:11           ` Philippe Mathieu-Daudé
2021-10-27 18:44           ` Richard Henderson
2021-10-28 12:03             ` Christian Schoenebeck
2021-10-27 16:01   ` Greg Kurz
2021-10-27 21:03 ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c0451f0bc4210d262268ff51c053a9277f20f862.1635340713.git.qemu_oss@crudebyte.com \
    --to=qemu_oss@crudebyte.com \
    --cc=groug@kaod.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.