[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 2/5] qemu/qarray.h: check scalar type in QARRAY_CREATE()
From: |
Christian Schoenebeck |
Subject: |
[PATCH v3 2/5] qemu/qarray.h: check scalar type in QARRAY_CREATE() |
Date: |
Thu, 26 Aug 2021 14:31:20 +0200 |
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 25af97a8a6..7adf28c03c 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
@@ -149,6 +151,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
- [PATCH v3 0/5] introduce QArray, Christian Schoenebeck, 2021/08/26
- [PATCH v3 1/5] qemu/qarray.h: introduce QArray, Christian Schoenebeck, 2021/08/26
- [PATCH v3 2/5] qemu/qarray.h: check scalar type in QARRAY_CREATE(),
Christian Schoenebeck <=
- [PATCH v3 3/5] 9pfs: make V9fsString usable via QArray API, Christian Schoenebeck, 2021/08/26
- [PATCH v3 4/5] 9pfs: make V9fsPath usable via QArray API, Christian Schoenebeck, 2021/08/26
- [PATCH v3 5/5] 9pfs: use QArray in v9fs_walk(), Christian Schoenebeck, 2021/08/26
- Re: [PATCH v3 0/5] introduce QArray, Greg Kurz, 2021/08/31