qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Christian Schoenebeck <qemu_oss@crudebyte.com>
To: qemu-devel@nongnu.org
Cc: Greg Kurz <groug@kaod.org>,
	Richard Henderson <richard.henderson@linaro.org>
Subject: [PATCH v2 2/5] qemu/qarray.h: check scalar type in QARRAY_CREATE()
Date: Sun, 22 Aug 2021 15:17:00 +0200	[thread overview]
Message-ID: <77d96c7e87c5f25e1e42319131f4d21ec646eb32.1629638507.git.qemu_oss@crudebyte.com> (raw)
In-Reply-To: <cover.1629638507.git.qemu_oss@crudebyte.com>

Make sure at compile time that the scalar type of the array
requested to be created via QARRAY_CREATE() 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>
---
 include/qemu/qarray.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/include/qemu/qarray.h b/include/qemu/qarray.h
index 9885e5e9ed..643c8877c5 100644
--- a/include/qemu/qarray.h
+++ b/include/qemu/qarray.h
@@ -27,6 +27,8 @@
 #ifndef QEMU_QARRAY_H
 #define QEMU_QARRAY_H
 
+#include "qemu/compiler.h"
+
 /**
  * QArray provides a mechanism to access arrays in common C-style (e.g. by
  * square bracket [] operator) in conjunction with reference variables that
@@ -145,6 +147,10 @@
  * @param len - amount of array elements to be allocated immediately
  */
 #define QARRAY_CREATE(scalar_type, auto_var, len) \
+    QEMU_BUILD_BUG_MSG( \
+        !__builtin_types_compatible_p(scalar_type, typeof(*auto_var)), \
+        "QArray scalar type mismatch" \
+    ); \
     qarray_create_##scalar_type((&auto_var), len)
 
 #endif /* QEMU_QARRAY_H */
-- 
2.20.1



  parent reply	other threads:[~2021-08-22 13:34 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-22 13:21 [PATCH v2 0/5] introduce QArray Christian Schoenebeck
2021-08-22 13:16 ` [PATCH v2 1/5] qemu/qarray.h: " Christian Schoenebeck
2021-08-24  8:22   ` Markus Armbruster
2021-08-24 11:51     ` Christian Schoenebeck
2021-08-24 14:45       ` Markus Armbruster
2021-08-24 15:24         ` Christian Schoenebeck
2021-08-24 15:28           ` Christian Schoenebeck
2021-08-25  8:15             ` Markus Armbruster
2021-08-24 11:58   ` Christian Schoenebeck
2021-08-24 14:21     ` Markus Armbruster
2021-09-28 13:04   ` Daniel P. Berrangé
2021-09-28 16:23     ` Christian Schoenebeck
2021-09-28 16:41       ` Daniel P. Berrangé
2021-09-29 17:32         ` Christian Schoenebeck
2021-09-29 17:48           ` Daniel P. Berrangé
2021-09-30 13:20             ` Christian Schoenebeck
2021-09-30 13:31               ` Daniel P. Berrangé
2021-09-30 13:55                 ` Christian Schoenebeck
2021-09-30 14:01                   ` Daniel P. Berrangé
2021-09-30 14:17                     ` Christian Schoenebeck
2021-08-22 13:17 ` Christian Schoenebeck [this message]
2021-08-22 13:17 ` [PATCH v2 3/5] 9pfs: make V9fsString usable via QArray API Christian Schoenebeck
2021-08-22 13:17 ` [PATCH v2 4/5] 9pfs: make V9fsPath " Christian Schoenebeck
2021-08-22 13:17 ` [PATCH v2 5/5] 9pfs: use QArray in v9fs_walk() Christian Schoenebeck

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=77d96c7e87c5f25e1e42319131f4d21ec646eb32.1629638507.git.qemu_oss@crudebyte.com \
    --to=qemu_oss@crudebyte.com \
    --cc=groug@kaod.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).