*/
static inline bool bytestring_eq(struct bytestring a, struct bytestring b)
{
- return (a.len == b.len)
- && (memcmp(a.ptr, b.ptr, a.len) == 0);
+ return memeq(a.ptr, a.len, b.ptr, b.len);
}
/**
static inline bool bytestring_starts(struct bytestring s,
struct bytestring prefix)
{
- return (s.len >= prefix.len) && (memcmp(s.ptr,
- prefix.ptr, prefix.len) == 0);
+ return memstarts(s.ptr, s.len, prefix.ptr, prefix.len);
}
/**
static inline bool bytestring_ends(struct bytestring s,
struct bytestring suffix)
{
- return (s.len >= suffix.len) && (memcmp(s.ptr + s.len - suffix.len,
- suffix.ptr, suffix.len) == 0);
+ return memends(s.ptr, s.len, suffix.ptr, suffix.len);
}
/**
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