summaryrefslogtreecommitdiff
path: root/include/string.h
diff options
context:
space:
mode:
authorjvoisin2024-03-08 16:07:57 +0100
committerjvoisin2024-03-08 16:28:52 +0100
commit140cffbe84a08669d67c3257258d2bb70ff29c3b (patch)
tree54a70b70f6fbe96840fa5fc9eb294c74f6855ad9 /include/string.h
parent2f60f255af5d615ca31d554035fe8268ecc9825c (diff)
Add some NULL-pointers checks
See: - https://www.imperialviolet.org/2016/06/26/nonnull.html - https://davidben.net/2024/01/15/empty-slices.html
Diffstat (limited to 'include/string.h')
-rw-r--r--include/string.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/string.h b/include/string.h
index 75dadab..24c1501 100644
--- a/include/string.h
+++ b/include/string.h
@@ -51,6 +51,9 @@ __error_if((__fh_bos(__od, 0) < __n), "'memcpy' called with `n` bigger than the
51#if __has_builtin(__builtin___memcpy_chk) && USE_NATIVE_CHK 51#if __has_builtin(__builtin___memcpy_chk) && USE_NATIVE_CHK
52 return __builtin___memcpy_chk(__od, __os, __n, __fh_bos(__od, 0)); 52 return __builtin___memcpy_chk(__od, __os, __n, __fh_bos(__od, 0));
53#else 53#else
54 if (!__od || !__os)
55 __builtin_trap();
56
54 __fh_size_t __bd = __fh_bos(__od, 0); 57 __fh_size_t __bd = __fh_bos(__od, 0);
55 __fh_size_t __bs = __fh_bos(__os, 0); 58 __fh_size_t __bs = __fh_bos(__os, 0);
56 char *__d = (char *)__od; 59 char *__d = (char *)__od;
@@ -75,6 +78,9 @@ _FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
75#if __has_builtin(__builtin___memmove_chk) && USE_NATIVE_CHK 78#if __has_builtin(__builtin___memmove_chk) && USE_NATIVE_CHK
76 return __builtin___memmove_chk(__d, __s, __n, __fh_bos(__d, 0)); 79 return __builtin___memmove_chk(__d, __s, __n, __fh_bos(__d, 0));
77#else 80#else
81 if (!__d || !__s)
82 __builtin_trap();
83
78 __fh_size_t __bd = __fh_bos(__d, 0); 84 __fh_size_t __bd = __fh_bos(__d, 0);
79 __fh_size_t __bs = __fh_bos(__s, 0); 85 __fh_size_t __bs = __fh_bos(__s, 0);
80 86
@@ -94,6 +100,9 @@ __warning_if(__c != 0 && __n == 0, "'memset' will set `0` bytes; did you invert
94#if __has_builtin(__builtin___memset_chk) && USE_NATIVE_CHK 100#if __has_builtin(__builtin___memset_chk) && USE_NATIVE_CHK
95 return __builtin___memset_chk(__d, __c, __n, __fh_bos(__d, 0)); 101 return __builtin___memset_chk(__d, __c, __n, __fh_bos(__d, 0));
96#else 102#else
103 if (!__d)
104 __builtin_trap();
105
97 __fh_size_t __b = __fh_bos(__d, 0); 106 __fh_size_t __b = __fh_bos(__d, 0);
98 107
99 if (__n > __b) 108 if (__n > __b)
@@ -111,6 +120,9 @@ _FORTIFY_FN(memchr) void *memchr(const void * _FORTIFY_POS0 __d, int __c, size_t
111#if __has_builtin(__builtin___memchr_chk) && USE_NATIVE_CHK 120#if __has_builtin(__builtin___memchr_chk) && USE_NATIVE_CHK
112 return __builtin___memchr_chk(__d, __c, __n, __fh_bos(__d, 0)); 121 return __builtin___memchr_chk(__d, __c, __n, __fh_bos(__d, 0));
113#else 122#else
123 if (!__d)
124 __builtin_trap();
125
114 __fh_size_t __b = __fh_bos(__d, 0); 126 __fh_size_t __b = __fh_bos(__d, 0);
115 127
116 if (__n > __b) 128 if (__n > __b)
@@ -322,6 +334,9 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
322#if __has_builtin(__builtin___mempcpy_chk) && USE_NATIVE_CHK 334#if __has_builtin(__builtin___mempcpy_chk) && USE_NATIVE_CHK
323 return __builtin___mempcpy_chk(__d, __s, __n, __fh_bos(__d, 0)); 335 return __builtin___mempcpy_chk(__d, __s, __n, __fh_bos(__d, 0));
324#else 336#else
337 if (!__d || !__s)
338 __builtin_trap();
339
325 __fh_size_t __bd = __fh_bos(__d, 0); 340 __fh_size_t __bd = __fh_bos(__d, 0);
326 __fh_size_t __bs = __fh_bos(__s, 0); 341 __fh_size_t __bs = __fh_bos(__s, 0);
327 342