summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston Sequoia <jeremyhu@apple.com>2013-12-29 11:26:00 -0800
committerJeremy Huddleston Sequoia <jeremyhu@apple.com>2013-12-29 11:26:00 -0800
commit3d8ec68e374a26f614e1715a1c2de653dd9b9eaf (patch)
treeb395bc46551231d528074ec9432d1e48f2687c56
parent1da35290c973aa725d69f89870a139bd06f11c78 (diff)
Silence clang static analysis warning by handling call to set 0 menu items better
applewm.c:273:21: warning: Call to 'alloca' has an allocation size of 0 bytes ptr = buf = alloca (total_length); ^~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
-rw-r--r--src/applewm.c40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/applewm.c b/src/applewm.c
index 95f0a68..2508403 100644
--- a/src/applewm.c
+++ b/src/applewm.c
@@ -253,9 +253,6 @@ Bool XAppleWMSetWindowMenuWithShortcuts(Display* dpy, int nitems,
{
XExtDisplayInfo *info = find_display (dpy);
xAppleWMSetWindowMenuReq *req;
- int i, total_length, len;
- char *buf, *ptr;
-
TRACE("SetWindowMenu...");
AppleWMCheckExtension (dpy, info, False);
@@ -265,26 +262,31 @@ Bool XAppleWMSetWindowMenuWithShortcuts(Display* dpy, int nitems,
req->wmReqType = X_AppleWMSetWindowMenu;
req->nitems = nitems;
- total_length = 0;
- for (i = 0; i < nitems; i++)
- total_length += strlen (items[i]) + 2;
-
- ptr = buf = alloca (total_length);
- for (i = 0; i < nitems; i++)
- {
- len = strlen (items[i]);
- *ptr++ = shortcuts ? shortcuts[i] : 0;
- memcpy (ptr, items[i], len);
- ptr[len] = 0;
- ptr += len + 1;
+ if (nitems > 0) {
+ char *buf, *ptr;
+ int i, len;
+
+ int total_length = 0;
+ for (i = 0; i < nitems; i++)
+ total_length += strlen (items[i]) + 2;
+
+ ptr = buf = alloca (total_length);
+ for (i = 0; i < nitems; i++)
+ {
+ len = strlen (items[i]);
+ *ptr++ = shortcuts ? shortcuts[i] : 0;
+ memcpy (ptr, items[i], len);
+ ptr[len] = 0;
+ ptr += len + 1;
+ }
+
+ req->length += (total_length + 3) >> 2;
+ Data (dpy, buf, total_length);
}
- req->length += (total_length + 3) >> 2;
- Data (dpy, buf, total_length);
-
UnlockDisplay(dpy);
SyncHandle();
- TRACE("SetlectInput... return True");
+ TRACE("SetWindowMenu... return True");
return True;
}