diff options
| author | jvoisin | 2023-09-11 17:41:31 +0200 |
|---|---|---|
| committer | jvoisin | 2023-09-11 17:41:31 +0200 |
| commit | 5ce4b94b7ac1d529b42ac76609b686d1ba0dffcb (patch) | |
| tree | 6aaff589e9e302b28a9e517a5f2247676454967d /include | |
| parent | 07da6751b9d1a6498e81c9d3b97ec3b552fa0b38 (diff) | |
Add the warn_unused_result attribute to alloc-related functions
Diffstat (limited to 'include')
| -rw-r--r-- | include/fortify-headers.h | 7 | ||||
| -rw-r--r-- | include/stdlib.h | 4 |
2 files changed, 11 insertions, 0 deletions
diff --git a/include/fortify-headers.h b/include/fortify-headers.h index dbace47..74c814b 100644 --- a/include/fortify-headers.h +++ b/include/fortify-headers.h | |||
| @@ -110,6 +110,13 @@ | |||
| 110 | #define __error_if(cond, msg) | 110 | #define __error_if(cond, msg) |
| 111 | #endif | 111 | #endif |
| 112 | 112 | ||
| 113 | #if __has_attribute (warn_unused_result) | ||
| 114 | #define __warn_unused_result __attribute__ ((warn_unused_result)) | ||
| 115 | #else | ||
| 116 | #define __warn_unused_result | ||
| 117 | #endif | ||
| 118 | |||
| 119 | |||
| 113 | #endif /* __has_attribute */ | 120 | #endif /* __has_attribute */ |
| 114 | 121 | ||
| 115 | /* | 122 | /* |
diff --git a/include/stdlib.h b/include/stdlib.h index 4efdb82..2671280 100644 --- a/include/stdlib.h +++ b/include/stdlib.h | |||
| @@ -42,6 +42,7 @@ extern "C" { | |||
| 42 | 42 | ||
| 43 | __malloc(malloc (free, 1)) | 43 | __malloc(malloc (free, 1)) |
| 44 | __alloc_size(1) | 44 | __alloc_size(1) |
| 45 | __warn_unused_result | ||
| 45 | __diagnose_as_builtin(__builtin_malloc, 1) | 46 | __diagnose_as_builtin(__builtin_malloc, 1) |
| 46 | _FORTIFY_FN(malloc) void *malloc(size_t __s) | 47 | _FORTIFY_FN(malloc) void *malloc(size_t __s) |
| 47 | { | 48 | { |
| @@ -49,6 +50,7 @@ _FORTIFY_FN(malloc) void *malloc(size_t __s) | |||
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | __alloc_size(2) | 52 | __alloc_size(2) |
| 53 | __warn_unused_result | ||
| 52 | __diagnose_as_builtin(__builtin_realloc, 1, 2) | 54 | __diagnose_as_builtin(__builtin_realloc, 1, 2) |
| 53 | _FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s) | 55 | _FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s) |
| 54 | { | 56 | { |
| @@ -56,6 +58,7 @@ _FORTIFY_FN(realloc) void *realloc(void *__p, size_t __s) | |||
| 56 | } | 58 | } |
| 57 | 59 | ||
| 58 | __alloc_size(1, 2) | 60 | __alloc_size(1, 2) |
| 61 | __warn_unused_result | ||
| 59 | __diagnose_as_builtin(__builtin_calloc, 1, 2) | 62 | __diagnose_as_builtin(__builtin_calloc, 1, 2) |
| 60 | _FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s) | 63 | _FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s) |
| 61 | { | 64 | { |
| @@ -65,6 +68,7 @@ _FORTIFY_FN(calloc) void *calloc(size_t __n, size_t __s) | |||
| 65 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | 68 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) |
| 66 | #undef reallocarray | 69 | #undef reallocarray |
| 67 | __alloc_size (2, 3) | 70 | __alloc_size (2, 3) |
| 71 | __warn_unused_result | ||
| 68 | __diagnose_as_builtin(__builtin_reallocarray, 1, 2, 3) | 72 | __diagnose_as_builtin(__builtin_reallocarray, 1, 2, 3) |
| 69 | _FORTIFY_FN(reallocarray) void* reallocarray(void* __p, size_t __n, size_t __s) | 73 | _FORTIFY_FN(reallocarray) void* reallocarray(void* __p, size_t __n, size_t __s) |
| 70 | { | 74 | { |
