diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2024-09-08 11:03:41 -0700 |
---|---|---|
committer | Marge Bot <emma+marge@anholt.net> | 2024-10-11 00:18:05 +0000 |
commit | 83a9950d7a8e365d13acaa1c38136d1b9068f4be (patch) | |
tree | a097a8b9f5d5d1322bfd5d0e5db3b102f6260a30 | |
parent | 3bca0f56fa509c57715ad9f2f1742d73f6ffee6d (diff) |
dix: dixChangeWindowProperty: don't call memcpy if malloc failed
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 <alan.coopersmith@oracle.com>
(cherry picked from commit 10cafd0bbebfbb92c4e73088ba168ef96fcb983c)
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1717>
-rw-r--r-- | dix/property.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/dix/property.c b/dix/property.c index acce94b2c..f7f9d0943 100644 --- a/dix/property.c +++ b/dix/property.c @@ -276,11 +276,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; @@ -313,9 +315,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; |