[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/2] Add QEMU_WARN_UNUSED_RESULT attribute
From: |
Philippe Mathieu-Daudé |
Subject: |
Re: [PATCH 1/2] Add QEMU_WARN_UNUSED_RESULT attribute |
Date: |
Fri, 10 Nov 2023 12:15:48 +0100 |
User-agent: |
Mozilla Thunderbird |
On 10/11/23 10:16, Manos Pitsidianakis wrote:
This commit adds QEMU_WARN_UNUSED_RESULT, a macro for the gcc function
attribute `warn_unused_result`. The utility of this attribute is to
ensure functions that return values that need to be inspected are not
ignored by the caller.
Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
---
include/qemu/compiler.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
+/*
+ * From GCC documentation:
+ *
+ * The warn_unused_result attribute causes a warning to be emitted if a
+ * caller of the function with this attribute does not use its return value.
+ * This is useful for functions where not checking the result is either a
+ * security problem or always a bug, such as realloc.
+ */
+#if __has_attribute(warn_unused_result)
+# define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
+#else
+# define QEMU_WARN_UNUSED_RESULT
+#endif
FWIW I sometimes use:
+#if __has_attribute(nonnull)
+# define QEMU_NONNULL(indexes...) __attribute__((nonnull((indexes))))
+#else
+# define QEMU_NONNULL(indexes...)
+#endif
when doing tree-wide refactors, then remove the attribute because
prototypes become really ugly.
- [PATCH 0/2] Add QEMU_WARN_UNUSED_RESULT function attribute, Manos Pitsidianakis, 2023/11/10
- [PATCH 1/2] Add QEMU_WARN_UNUSED_RESULT attribute, Manos Pitsidianakis, 2023/11/10
- [PATCH 2/2] Add warn_unused_result attr to AUD_register_card, Manos Pitsidianakis, 2023/11/10
- Re: [PATCH 2/2] Add warn_unused_result attr to AUD_register_card, Daniel P . Berrangé, 2023/11/10
- Re: [PATCH 2/2] Add warn_unused_result attr to AUD_register_card, Manos Pitsidianakis, 2023/11/10
- Re: [PATCH 2/2] Add warn_unused_result attr to AUD_register_card, BALATON Zoltan, 2023/11/10
- Re: [PATCH 2/2] Add warn_unused_result attr to AUD_register_card, Daniel P . Berrangé, 2023/11/10