static int ProcAppleWMSetWindowMenu(register ClientPtr client) { const char *bytes, **items; char *shortcuts; int max_len, nitems, i, j; REQUEST(xAppleWMSetWindowMenuReq); REQUEST_AT_LEAST_SIZE(xAppleWMSetWindowMenuReq); nitems = stuff->nitems; items = malloc(sizeof(char *) * nitems); shortcuts = malloc(sizeof(char) * nitems); if (!items || !shortcuts) { free(items); free(shortcuts); return BadAlloc; } max_len = (stuff->length << 2) - sizeof(xAppleWMSetWindowMenuReq); bytes = (char *)&stuff[1]; for (i = j = 0; i < max_len && j < nitems;) { shortcuts[j] = bytes[i++]; items[j++] = bytes + i; while (i < max_len) { if (bytes[i++] == 0) break; } } /* Check if we bailed out of the above loop due to a request that was too long */ if (j < nitems) { free(items); free(shortcuts); return BadRequest; } X11ApplicationSetWindowMenu(nitems, items, shortcuts); free(items); free(shortcuts); return Success; }
static int ProcAppleWMSetWindowMenu( register ClientPtr client ) { const char *bytes, **items; char *shortcuts; int max_len, nitems, i, j; REQUEST(xAppleWMSetWindowMenuReq); REQUEST_AT_LEAST_SIZE(xAppleWMSetWindowMenuReq); nitems = stuff->nitems; items = xalloc (sizeof (char *) * nitems); shortcuts = xalloc (sizeof (char) * nitems); max_len = (stuff->length << 2) - sizeof(xAppleWMSetWindowMenuReq); bytes = (char *) &stuff[1]; for (i = j = 0; i < max_len && j < nitems;) { shortcuts[j] = bytes[i++]; items[j++] = bytes + i; while (i < max_len) { if (bytes[i++] == 0) break; } } X11ApplicationSetWindowMenu (nitems, items, shortcuts); free(items); free(shortcuts); return (client->noClientException); }