I swear the C standards committee likes compilers more than they like
programmers :(
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
static inline struct bytestring bytestring_bytestring(struct bytestring haystack,
struct bytestring needle)
{
static inline struct bytestring bytestring_bytestring(struct bytestring haystack,
struct bytestring needle)
{
- const char *p = memmem(haystack.ptr, haystack.len,
- needle.ptr, needle.len);
+ const char *p;
+
+ /* Allow needle.ptr == NULL, without memmem sanitizer complaining */
+ if (needle.len == 0)
+ return bytestring(haystack.ptr, 0);
+
+ p = memmem(haystack.ptr, haystack.len, needle.ptr, needle.len);
if (p)
return bytestring(p, needle.len);
else
if (p)
return bytestring(p, needle.len);
else
* (e.g., if K is of length 20 bytes and B=64, then K will be
* appended with 44 zero bytes 0x00)
*/
* (e.g., if K is of length 20 bytes and B=64, then K will be
* appended with 44 zero bytes 0x00)
*/
- memcpy(k_ipad, k, ksize);
+ if (ksize != 0)
+ memcpy(k_ipad, k, ksize);
memset((char *)k_ipad + ksize, 0, HMAC_SHA256_BLOCKSIZE - ksize);
/*
memset((char *)k_ipad + ksize, 0, HMAC_SHA256_BLOCKSIZE - ksize);
/*
#define darray_append_items(arr, items, count) do { \
size_t count_ = (count), oldSize_ = (arr).size; \
#define darray_append_items(arr, items, count) do { \
size_t count_ = (count), oldSize_ = (arr).size; \
- darray_resize(arr, oldSize_ + count_); \
- memcpy((arr).item + oldSize_, items, count_ * sizeof(*(arr).item)); \
+ /* Don't memcpy NULL! */ \
+ if (count_) { \
+ darray_resize(arr, oldSize_ + count_); \
+ memcpy((arr).item + oldSize_, items, count_ * sizeof(*(arr).item)); \
+ } \
} while(0)
#define darray_prepend_items(arr, items, count) do { \
size_t count_ = (count), oldSize_ = (arr).size; \
darray_resize(arr, count_ + oldSize_); \
} while(0)
#define darray_prepend_items(arr, items, count) do { \
size_t count_ = (count), oldSize_ = (arr).size; \
darray_resize(arr, count_ + oldSize_); \
- memmove((arr).item + count_, (arr).item, oldSize_ * sizeof(*(arr).item)); \
- memcpy((arr).item, items, count_ * sizeof(*(arr).item)); \
+ /* Don't memcpy NULL! */ \
+ if (count_) { \
+ memmove((arr).item + count_, (arr).item, oldSize_ * sizeof(*(arr).item)); \
+ memcpy((arr).item, items, count_ * sizeof(*(arr).item)); \
+ } \
} while(0)
#define darray_append_items_nullterminate(arr, items, count) do { \
} while(0)
#define darray_append_items_nullterminate(arr, items, count) do { \
PURE_FUNCTION
static inline bool memeq(const void *a, size_t al, const void *b, size_t bl)
{
PURE_FUNCTION
static inline bool memeq(const void *a, size_t al, const void *b, size_t bl)
{
- return al == bl && !memcmp(a, b, bl);
+ return al == bl && (al == 0 || !memcmp(a, b, bl));
}
ret = tal_alloc_arr_(ctx, size, n + extra, false, label);
}
ret = tal_alloc_arr_(ctx, size, n + extra, false, label);
memcpy(ret, p, nbytes);
return ret;
}
memcpy(ret, p, nbytes);
return ret;
}