diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2024-12-16 12:49:42 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2024-12-16 12:57:51 -0500 |
commit | 77211ec0866344655c439839753653234a5e281e (patch) | |
tree | a48b2a02a4aa74476d610de0c39220a5b8f5bf51 /src/sanity.h | |
parent | ce378308af700657d9cba841939b2385b21accaa (diff) | |
download | bfs-77211ec0866344655c439839753653234a5e281e.tar.xz |
sanity: New sanitize_resize() function
This wraps __sanitizer_annotate_contiguous_container() to give
byte-precise tracking of usable allocation sizes with ASan.
Diffstat (limited to 'src/sanity.h')
-rw-r--r-- | src/sanity.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/sanity.h b/src/sanity.h index 89d0e4f..be77eef 100644 --- a/src/sanity.h +++ b/src/sanity.h @@ -37,9 +37,27 @@ */ #define sanitize_free(...) SANITIZE_CALL(__asan_poison_memory_region, __VA_ARGS__) +/** + * Adjust the size of an allocated region, for things like dynamic arrays. + * + * @ptr + * The memory region. + * @old + * The previous usable size of the region. + * @new + * The new usable size of the region. + * @cap + * The total allocated capacity of the region. + */ +static inline void sanitize_resize(const void *ptr, size_t old, size_t new, size_t cap) { + const char *beg = ptr; + __sanitizer_annotate_contiguous_container(beg, beg + cap, beg + old, beg + new); +} + #else # define sanitize_alloc(...) ((void)0) # define sanitize_free(...) ((void)0) +# define sanitize_resize(ptr, old, new, cap) ((void)0) #endif #if __SANITIZE_MEMORY__ |