From 10cafd0bbebfbb92c4e73088ba168ef96fcb983c Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 8 Sep 2024 11:03:41 -0700 Subject: [PATCH] dix: dixChangeWindowProperty: don't call memcpy if malloc failed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It shouldn't matter, since it would have a length of 0, but it clears warnings from gcc 14.1: ../dix/property.c: In function ‘dixChangeWindowProperty’: ../dix/property.c:287:9: warning: use of possibly-NULL ‘data’ where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument] 287 | memcpy(data, value, totalSize); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../dix/property.c:324:13: warning: use of possibly-NULL ‘data’ where non-null expected [CWE-690] [-Wanalyzer-possible-null-argument] 324 | memcpy(data, value, totalSize); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Alan Coopersmith Part-of: --- dix/property.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/dix/property.c b/dix/property.c index 435450973..b51b371f0 100644 --- a/dix/property.c +++ b/dix/property.c @@ -280,11 +280,13 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, if (!pProp) return BadAlloc; data = malloc(totalSize); - if (!data && len) { - dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); - return BadAlloc; + if (totalSize) { + if (!data) { + dixFreeObjectWithPrivates(pProp, PRIVATE_PROPERTY); + return BadAlloc; + } + memcpy(data, value, totalSize); } - memcpy(data, value, totalSize); pProp->propertyName = property; pProp->type = type; pProp->format = format; @@ -317,9 +319,11 @@ dixChangeWindowProperty(ClientPtr pClient, WindowPtr pWin, Atom property, if (mode == PropModeReplace) { data = malloc(totalSize); - if (!data && len) - return BadAlloc; - memcpy(data, value, totalSize); + if (totalSize) { + if (!data) + return BadAlloc; + memcpy(data, value, totalSize); + } pProp->data = data; pProp->size = len; pProp->type = type;