Page MenuHomeFreeBSD

D58773.id.diff
No OneTemporary

D58773.id.diff

diff --git a/include/stdckdint.h b/include/stdckdint.h
--- a/include/stdckdint.h
+++ b/include/stdckdint.h
@@ -7,33 +7,11 @@
#ifndef __STDC_VERSION_STDCKDINT_H__
#define __STDC_VERSION_STDCKDINT_H__ 202311L
-#include <sys/cdefs.h>
+#include <sys/_visible.h>
#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 2023
-#if __GNUC_PREREQ__(5, 1) || __has_builtin(__builtin_add_overflow)
-#define ckd_add(result, a, b) \
- __builtin_add_overflow((a), (b), (result))
-#else
-#define ckd_add(result, a, b) \
- _Static_assert(0, "checked addition not supported")
-#endif
-
-#if __GNUC_PREREQ__(5, 1) || __has_builtin(__builtin_sub_overflow)
-#define ckd_sub(result, a, b) \
- __builtin_sub_overflow((a), (b), (result))
-#else
-#define ckd_sub(result, a, b) \
- _Static_assert(0, "checked subtraction not supported")
-#endif
-
-#if __GNUC_PREREQ__(5, 1) || __has_builtin(__builtin_mul_overflow)
-#define ckd_mul(result, a, b) \
- __builtin_mul_overflow((a), (b), (result))
-#else
-#define ckd_mul(result, a, b) \
- _Static_assert(0, "checked multiplication not supported")
-#endif
+#include <sys/ckdint.h>
#endif
diff --git a/include/stdckdint.h b/sys/sys/ckdint.h
copy from include/stdckdint.h
copy to sys/sys/ckdint.h
--- a/include/stdckdint.h
+++ b/sys/sys/ckdint.h
@@ -4,16 +4,25 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#ifndef __STDC_VERSION_STDCKDINT_H__
-#define __STDC_VERSION_STDCKDINT_H__ 202311L
+#ifndef _SYS_CKDINT_H_
+#define _SYS_CKDINT_H_
#include <sys/cdefs.h>
-#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 2023
+#ifdef _KERNEL
+/* If you're not checking the return value, what's the point? */
+__nodiscard static inline bool
+__ckd_result(bool result)
+{
+ return (result);
+}
+#else
+#define __ckd_result(result) (result)
+#endif
#if __GNUC_PREREQ__(5, 1) || __has_builtin(__builtin_add_overflow)
#define ckd_add(result, a, b) \
- __builtin_add_overflow((a), (b), (result))
+ __ckd_result(__builtin_add_overflow((a), (b), (result)))
#else
#define ckd_add(result, a, b) \
_Static_assert(0, "checked addition not supported")
@@ -21,7 +30,7 @@
#if __GNUC_PREREQ__(5, 1) || __has_builtin(__builtin_sub_overflow)
#define ckd_sub(result, a, b) \
- __builtin_sub_overflow((a), (b), (result))
+ __ckd_result(__builtin_sub_overflow((a), (b), (result)))
#else
#define ckd_sub(result, a, b) \
_Static_assert(0, "checked subtraction not supported")
@@ -29,12 +38,10 @@
#if __GNUC_PREREQ__(5, 1) || __has_builtin(__builtin_mul_overflow)
#define ckd_mul(result, a, b) \
- __builtin_mul_overflow((a), (b), (result))
+ __ckd_result(__builtin_mul_overflow((a), (b), (result)))
#else
#define ckd_mul(result, a, b) \
_Static_assert(0, "checked multiplication not supported")
#endif
-#endif
-
-#endif
+#endif /* _SYS_CKDINT_H_ */

File Metadata

Mime Type
text/plain
Expires
Wed, Aug 19, 5:06 AM (6 h, 32 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
36918127
Default Alt Text
D58773.id.diff (2 KB)

Event Timeline