X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fmem%2Fmem.h;h=f2c3d5c7a6f795e2e091df8a545992c6533b50ec;hp=06a1b7a1f2411150147d043cc0bfdbf7635967e8;hb=a934320836ffaad26be1e3160df30ef7350c39d5;hpb=299170fa67ff3cf664cbcd2c95c4a85d0d6e699d diff --git a/ccan/mem/mem.h b/ccan/mem/mem.h index 06a1b7a1..f2c3d5c7 100644 --- a/ccan/mem/mem.h +++ b/ccan/mem/mem.h @@ -144,7 +144,10 @@ static inline bool memstarts(void const *data, size_t data_len, * } */ PURE_FUNCTION -bool memeqzero(const void *data, size_t length); +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? @@ -157,10 +160,7 @@ bool memeqzero(const void *data, size_t length); * } */ PURE_FUNCTION -static inline bool memeqstr(const void *data, size_t length, const char *string) -{ - return memeq(data, length, string, strlen(string)); -} +bool memeqzero(const void *data, size_t length); /** * memstarts_str - Does this byte array start with a string prefix? @@ -275,4 +275,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 */