From 5b941666e9053348d51113b2fa8dd7e62e01f1ab Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 8 Oct 2020 11:51:42 +0200 Subject: [PATCH] shared: add NM_HASH_OBFUSCATE_PTR_STR() helper macro Contrary to NM_HASH_OBFUSCATE_PTR(), this allows to special case a %NULL pointer. Also, it quotes the obfuscated value in square brackets. --- shared/nm-glib-aux/nm-hash-utils.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shared/nm-glib-aux/nm-hash-utils.h b/shared/nm-glib-aux/nm-hash-utils.h index 1cfdcaf6e9..6028bb3d74 100644 --- a/shared/nm-glib-aux/nm-hash-utils.h +++ b/shared/nm-glib-aux/nm-hash-utils.h @@ -416,6 +416,14 @@ nm_hash_obfuscate_ptr(guint static_seed, gconstpointer val) * values in a global context. */ #define NM_HASH_OBFUSCATE_PTR(ptr) (nm_hash_obfuscate_ptr(1678382159u, ptr)) +#define NM_HASH_OBFUSCATE_PTR_STR(ptr, buf) \ + ({ \ + gconstpointer _ptr = (ptr); \ + \ + _ptr ? nm_sprintf_buf(buf, "[" NM_HASH_OBFUSCATE_PTR_FMT "]", NM_HASH_OBFUSCATE_PTR(_ptr)) \ + : "(null)"; \ + }) + static inline const char * nm_hash_obfuscated_ptr_str(gconstpointer ptr, char buf[static 17]) {