[glib/wip/smcv/memcmp-null: 2/2] gbytes: Avoid memcmp (NULL, ., 0) or memcmp (., NULL, 0)
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/smcv/memcmp-null: 2/2] gbytes: Avoid memcmp (NULL, ., 0) or memcmp (., NULL, 0)
- Date: Mon, 4 Nov 2019 15:11:13 +0000 (UTC)
commit 8235bbe467be78befe56e7a5dc914e5e35785fa3
Author: Simon McVittie <smcv collabora com>
Date: Mon Nov 4 13:41:14 2019 +0000
gbytes: Avoid memcmp (NULL, ., 0) or memcmp (., NULL, 0)
Similar to 3837b83f, glibc memcmp is declared with the first two
arguments annotated as non-null via an attribute, which results in the
undefined behaviour sanitizer considering it to be UB to pass a null
pointer there (even if we are comparing 0 bytes, and hence not actually
dereferencing the pointer).
This shows up in /gvariant/serialiser/children when run with the
undefined behaviour sanitizer.
Signed-off-by: Simon McVittie <smcv collabora com>
glib/gbytes.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
---
diff --git a/glib/gbytes.c b/glib/gbytes.c
index 7b72886e5..ec6923188 100644
--- a/glib/gbytes.c
+++ b/glib/gbytes.c
@@ -365,7 +365,7 @@ g_bytes_equal (gconstpointer bytes1,
g_return_val_if_fail (bytes2 != NULL, FALSE);
return b1->size == b2->size &&
- memcmp (b1->data, b2->data, b1->size) == 0;
+ (b1->size == 0 || memcmp (b1->data, b2->data, b1->size) == 0);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]