Avoid undefined behaviour in eq_var(p1, p2, field)

memcmp((p1)->field, (p2)->field, ...) results in undefined behaviour
if (p1)->field or (p2)->field is NULL. This holds also when
tal_count((p1)->field) * sizeof(*(p1)->field) == 0.
This commit is contained in:
practicalswift 2018-01-02 14:25:43 +01:00 committed by Rusty Russell
parent 6757255ba4
commit 7b80e5b66c

View File

@ -68,7 +68,8 @@ static void set_pubkey(struct pubkey *key)
sizeof((p1)->field)) == 0)
#define eq_var(p1, p2, field) \
(tal_count((p1)->field) == tal_count((p2)->field) && memcmp((p1)->field, (p2)->field, tal_count((p1)->field) * sizeof(*(p1)->field)) == 0)
(tal_count((p1)->field) == tal_count((p2)->field) \
&& (tal_count((p1)->field) == 0 || memcmp((p1)->field, (p2)->field, tal_len((p1)->field)) == 0))
/* Convenience structs for everyone! */
struct msg_error {