X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fmem%2Fmem.h;h=19f69c038c67efe1e11ac8ab5cec036123aa3b95;hb=996d4d12ddd52de579b5026bfbe9c65e26f6c698;hp=68a4aa3c18885c207a9fd11828bc5174bead6905;hpb=e8d1e7304feb9318a841ad4a7d5a8773271ab814;p=ccan diff --git a/ccan/mem/mem.h b/ccan/mem/mem.h index 68a4aa3c..19f69c03 100644 --- a/ccan/mem/mem.h +++ b/ccan/mem/mem.h @@ -149,6 +149,19 @@ static inline bool memeqstr(const void *data, size_t length, const char *string) return memeq(data, length, string, strlen(string)); } +/** + * memeqzero - Is a byte array all zeroes? + * @data: byte array + * @length: length of @data in bytes + * + * Example: + * if (memeqzero(somebytes, bytes_len)) { + * printf("somebytes == 0!\n"); + * } + */ +PURE_FUNCTION +bool memeqzero(const void *data, size_t length); + /** * memstarts_str - Does this byte array start with a string prefix? * @a: byte array @@ -237,6 +250,7 @@ static inline void *memcheck_(const void *data, size_t len) #else static inline void *memcheck_(const void *data, size_t len) { + (void)len; return (void *)data; } #endif @@ -262,4 +276,20 @@ static inline void *memcheck_(const void *data, size_t len) #else #define memcheck(data, len) memcheck_((data), (len)) #endif + +/** + * memtaint - mark a memory region unused + * @data: start of region + * @len: length in bytes + * + * This writes an "0xdeadbeef" eyecatcher repeatedly to the memory. + * When running under valgrind, it also tells valgrind that the memory is + * uninitialized, triggering valgrind errors if it is used for branches + * or written out (or passed to memcheck!) in future. + * + * Example: + * // We'll reuse this buffer later, but be sure we don't access it. + * memtaint(somebytes, bytes_len); + */ +void memtaint(void *data, size_t len); #endif /* CCAN_MEM_H */