[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/5] fsdev/p9array.h: check scalar type in P9ARRAY_NEW()
From: |
Christian Schoenebeck |
Subject: |
[PATCH 2/5] fsdev/p9array.h: check scalar type in P9ARRAY_NEW() |
Date: |
Fri, 1 Oct 2021 16:27:13 +0200 |
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>
---
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
- [PATCH 0/5] 9pfs: introduce P9Array, Christian Schoenebeck, 2021/10/01
- [PATCH 1/5] 9pfs: introduce P9Array, Christian Schoenebeck, 2021/10/01
- [PATCH 2/5] fsdev/p9array.h: check scalar type in P9ARRAY_NEW(),
Christian Schoenebeck <=
- [PATCH 3/5] 9pfs: make V9fsString usable via P9Array API, Christian Schoenebeck, 2021/10/01
- [PATCH 4/5] 9pfs: make V9fsPath usable via P9Array API, Christian Schoenebeck, 2021/10/01
- [PATCH 5/5] 9pfs: use P9Array in v9fs_walk(), Christian Schoenebeck, 2021/10/01
- Re: [PATCH 0/5] 9pfs: introduce P9Array, Christian Schoenebeck, 2021/10/14