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.
This commit is contained in:
Thomas Haller 2020-10-08 11:51:42 +02:00
parent 621ca03b33
commit 5b941666e9
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -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])
{