summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-07-14 20:08:39 +0200
committerThomas Haller <thaller@redhat.com>2022-07-20 10:15:23 +0200
commit2ebc3ac7d9d9ef5886c433d2e8df9d058631b524 (patch)
treee9f1b2034c30e807777e409216fb4cd040010e39
parent93372e81001baa2278cee1c83115b55f077033a6 (diff)
downloadNetworkManager-2ebc3ac7d9d9ef5886c433d2e8df9d058631b524.tar.gz
std-aux: add nm_memcmp() helper
-rw-r--r--src/libnm-std-aux/nm-std-aux.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h
index 059b6b83fa..8072e606c9 100644
--- a/src/libnm-std-aux/nm-std-aux.h
+++ b/src/libnm-std-aux/nm-std-aux.h
@@ -487,6 +487,17 @@ nm_streq0(const char *s1, const char *s2)
return (s1 == s2) || (s1 && s2 && strcmp(s1, s2) == 0);
}
+static inline int
+nm_memcmp(const void *s1, const void *s2, size_t n)
+{
+ /* Workaround undefined behavior in memcmp() with NULL pointers. */
+ if (n == 0)
+ return 0;
+ nm_assert(s1);
+ nm_assert(s2);
+ return memcmp(s1, s2, n);
+}
+
/*
* Very similar to g_str_has_prefix() with the obvious meaning.
* Differences: