X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fbytestring%2Fbytestring.h;fp=ccan%2Fbytestring%2Fbytestring.h;h=a0689db15b2f4457a9a15525edf08ee5ae4b55f2;hp=bc99e7951c739e94221148e12491ea994642fbae;hb=9e800830de8a9bbb9f103f120ea7de9220b6869d;hpb=e46957c87a57ff2efd0b23e230599cce529f1f92 diff --git a/ccan/bytestring/bytestring.h b/ccan/bytestring/bytestring.h index bc99e795..a0689db1 100644 --- a/ccan/bytestring/bytestring.h +++ b/ccan/bytestring/bytestring.h @@ -203,8 +203,13 @@ static inline const char *bytestring_rindex(struct bytestring haystack, 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