diff options
Diffstat (limited to 'nx-X11/lib/src/xkb')
-rw-r--r-- | nx-X11/lib/src/xkb/XKB.c | 2 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBAlloc.c | 65 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBBind.c | 22 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBExtDev.c | 2 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBGAlloc.c | 6 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBGetByName.c | 12 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBGetMap.c | 21 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBList.c | 14 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBMAlloc.c | 137 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBMisc.c | 14 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBNames.c | 10 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBRdBuf.c | 2 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBSetGeom.c | 18 | ||||
-rw-r--r-- | nx-X11/lib/src/xkb/XKBlibint.h | 22 |
14 files changed, 124 insertions, 223 deletions
diff --git a/nx-X11/lib/src/xkb/XKB.c b/nx-X11/lib/src/xkb/XKB.c index 6df9c3ebc..f5317afdb 100644 --- a/nx-X11/lib/src/xkb/XKB.c +++ b/nx-X11/lib/src/xkb/XKB.c @@ -406,7 +406,7 @@ XkbSetDebuggingFlags(Display *dpy, if (msg) { char *out; - req->msgLength = (unsigned short) strlen(msg) + 1; + req->msgLength = (CARD16) (strlen(msg) + 1); req->length += (req->msgLength + (unsigned) 3) >> 2; BufAlloc(char *, out, ((req->msgLength + (unsigned) 3) / 4) * 4); memcpy(out, msg, req->msgLength); diff --git a/nx-X11/lib/src/xkb/XKBAlloc.c b/nx-X11/lib/src/xkb/XKBAlloc.c index 5621f713a..ff6aabd4f 100644 --- a/nx-X11/lib/src/xkb/XKBAlloc.c +++ b/nx-X11/lib/src/xkb/XKBAlloc.c @@ -44,7 +44,6 @@ Status XkbAllocCompatMap(XkbDescPtr xkb, unsigned which, unsigned nSI) { XkbCompatMapPtr compat; - XkbSymInterpretRec *prev_interpret; if (!xkb) return BadMatch; @@ -55,18 +54,12 @@ XkbAllocCompatMap(XkbDescPtr xkb, unsigned which, unsigned nSI) compat->size_si = nSI; if (compat->sym_interpret == NULL) compat->num_si = 0; - prev_interpret = compat->sym_interpret; - compat->sym_interpret = _XkbTypedRealloc(compat->sym_interpret, - nSI, XkbSymInterpretRec); + _XkbResizeArray(compat->sym_interpret, compat->num_si, + nSI, XkbSymInterpretRec); if (compat->sym_interpret == NULL) { - _XkbFree(prev_interpret); compat->size_si = compat->num_si = 0; return BadAlloc; } - if (compat->num_si != 0) { - _XkbClearElems(compat->sym_interpret, compat->num_si, - compat->size_si - 1, XkbSymInterpretRec); - } return Success; } compat = _XkbTypedCalloc(1, XkbCompatMapRec); @@ -150,22 +143,10 @@ XkbAllocNames(XkbDescPtr xkb, unsigned which, int nTotalRG, int nTotalAliases) return BadAlloc; } if ((which & XkbKeyAliasesMask) && (nTotalAliases > 0)) { - if (names->key_aliases == NULL) { - names->key_aliases = _XkbTypedCalloc(nTotalAliases, XkbKeyAliasRec); - } - else if (nTotalAliases > names->num_key_aliases) { - XkbKeyAliasRec *prev_aliases = names->key_aliases; - - names->key_aliases = _XkbTypedRealloc(names->key_aliases, - nTotalAliases, - XkbKeyAliasRec); - if (names->key_aliases != NULL) { - _XkbClearElems(names->key_aliases, names->num_key_aliases, - nTotalAliases - 1, XkbKeyAliasRec); - } - else { - _XkbFree(prev_aliases); - } + if ((names->key_aliases == NULL) || + (nTotalAliases > names->num_key_aliases)) { + _XkbResizeArray(names->key_aliases, names->num_key_aliases, + nTotalAliases, XkbKeyAliasRec); } if (names->key_aliases == NULL) { names->num_key_aliases = 0; @@ -174,24 +155,13 @@ XkbAllocNames(XkbDescPtr xkb, unsigned which, int nTotalRG, int nTotalAliases) names->num_key_aliases = nTotalAliases; } if ((which & XkbRGNamesMask) && (nTotalRG > 0)) { - if (names->radio_groups == NULL) { - names->radio_groups = _XkbTypedCalloc(nTotalRG, Atom); + if ((names->radio_groups == NULL) || (nTotalRG > names->num_rg)) { + _XkbResizeArray(names->radio_groups, names->num_rg, nTotalRG, Atom); } - else if (nTotalRG > names->num_rg) { - Atom *prev_radio_groups = names->radio_groups; - - names->radio_groups = - _XkbTypedRealloc(names->radio_groups, nTotalRG, Atom); - if (names->radio_groups != NULL) { - _XkbClearElems(names->radio_groups, names->num_rg, nTotalRG - 1, - Atom); - } - else { - _XkbFree(prev_radio_groups); - } - } - if (names->radio_groups == NULL) + if (names->radio_groups == NULL) { + names->num_rg = 0; return BadAlloc; + } names->num_rg = nTotalRG; } return Success; @@ -350,16 +320,13 @@ XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi, unsigned ledClass, unsigned ledId) return devli; } if (devi->num_leds >= devi->sz_leds) { - XkbDeviceLedInfoRec *prev_leds = devi->leds; - if (devi->sz_leds > 0) devi->sz_leds *= 2; else devi->sz_leds = 1; - devi->leds = _XkbTypedRealloc(devi->leds, devi->sz_leds, - XkbDeviceLedInfoRec); + _XkbResizeArray(devi->leds, devi->num_leds, devi->sz_leds, + XkbDeviceLedInfoRec); if (!devi->leds) { - _XkbFree(prev_leds); devi->sz_leds = devi->num_leds = 0; return NULL; } @@ -380,8 +347,6 @@ XkbAddDeviceLedInfo(XkbDeviceInfoPtr devi, unsigned ledClass, unsigned ledId) Status XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi, unsigned newTotal) { - XkbAction *prev_btn_acts; - if ((!devi) || (newTotal > 255)) return BadValue; if ((devi->btn_acts != NULL) && (newTotal == devi->num_btns)) @@ -394,10 +359,8 @@ XkbResizeDeviceButtonActions(XkbDeviceInfoPtr devi, unsigned newTotal) devi->num_btns = 0; return Success; } - prev_btn_acts = devi->btn_acts; - devi->btn_acts = _XkbTypedRealloc(devi->btn_acts, newTotal, XkbAction); + _XkbResizeArray(devi->btn_acts, devi->num_btns, newTotal, XkbAction); if (devi->btn_acts == NULL) { - _XkbFree(prev_btn_acts); devi->num_btns = 0; return BadAlloc; } diff --git a/nx-X11/lib/src/xkb/XKBBind.c b/nx-X11/lib/src/xkb/XKBBind.c index ffe5ad9d7..726f3b2cc 100644 --- a/nx-X11/lib/src/xkb/XKBBind.c +++ b/nx-X11/lib/src/xkb/XKBBind.c @@ -179,7 +179,7 @@ XKeysymToKeycode(Display *dpy, KeySym ks) for (i = dpy->min_keycode; i <= dpy->max_keycode; i++) { if (j < (int) XkbKeyNumSyms(xkb, i)) { gotOne = 1; - if (XkbKeySym(xkb, i, j) == ks) + if ((XkbKeySym(xkb, i, j) == ks)) return i; } } @@ -236,7 +236,21 @@ XLookupKeysym(register XKeyEvent * event, int col) if (_XkbUnavailable(dpy)) return _XLookupKeysym(event, col); _XkbCheckPendingRefresh(dpy, dpy->xkb_info); + +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif return XKeycodeToKeysym(dpy, event->keycode, col); +#ifdef __clang__ +#pragma clang diagnostic pop +#elif defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + } /* @@ -601,8 +615,8 @@ _XkbReloadDpy(Display *dpy) } int -XkbTranslateKeySym(register Display *dpy, - register KeySym *sym_rtrn, +XkbTranslateKeySym(Display *dpy, + KeySym *sym_rtrn, unsigned int mods, char *buffer, int nbytes, @@ -770,7 +784,7 @@ XkbLookupKeyBinding(Display *dpy, *extra_rtrn = (tmp - nbytes); tmp = nbytes; } - memcpy(buffer, p->string, tmp); + memcpy(buffer, p->string, (size_t) tmp); if (tmp < nbytes) buffer[tmp] = '\0'; return tmp; diff --git a/nx-X11/lib/src/xkb/XKBExtDev.c b/nx-X11/lib/src/xkb/XKBExtDev.c index cb40ecd04..671f308c9 100644 --- a/nx-X11/lib/src/xkb/XKBExtDev.c +++ b/nx-X11/lib/src/xkb/XKBExtDev.c @@ -651,7 +651,7 @@ _XkbWriteSetDeviceInfo(char *wire, if (changes->changed & XkbXI_ButtonActionsMask) { int size = changes->num_btns * SIZEOF(xkbActionWireDesc); - memcpy(wire, (char *) &devi->btn_acts[changes->first_btn], size); + memcpy(wire, (char *) &devi->btn_acts[changes->first_btn], (size_t) size); wire += size; } if (changes->changed & XkbXI_IndicatorsMask) { diff --git a/nx-X11/lib/src/xkb/XKBGAlloc.c b/nx-X11/lib/src/xkb/XKBGAlloc.c index ab05f8d88..724228ddf 100644 --- a/nx-X11/lib/src/xkb/XKBGAlloc.c +++ b/nx-X11/lib/src/xkb/XKBGAlloc.c @@ -69,8 +69,8 @@ _XkbFreeGeomLeafElems(Bool freeAll, ptr = *elems; extra = ((*num_inout) - (first + count)) * elem_sz; if (extra > 0) - memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz], - extra); + memmove(&ptr[(unsigned) first * elem_sz], &ptr[(unsigned)(first + count) * elem_sz], + (size_t) extra); (*num_inout) -= count; } return; @@ -124,7 +124,7 @@ _XkbFreeGeomNonLeafElems(Bool freeAll, else { i = ((*num_inout) - (first + count)) * elem_sz; ptr = *elems; - memmove(&ptr[first * elem_sz], &ptr[(first + count) * elem_sz], i); + memmove(&ptr[(unsigned) first * elem_sz], &ptr[(unsigned)(first + count) * elem_sz], (size_t) i); (*num_inout) -= count; } return; diff --git a/nx-X11/lib/src/xkb/XKBGetByName.c b/nx-X11/lib/src/xkb/XKBGetByName.c index c673781ed..99dcd7405 100644 --- a/nx-X11/lib/src/xkb/XKBGetByName.c +++ b/nx-X11/lib/src/xkb/XKBGetByName.c @@ -109,32 +109,32 @@ XkbGetKeyboardByName(Display *dpy, *str++ = mapLen; if (mapLen > 0) { - memcpy(str, names->keymap, mapLen); + memcpy(str, names->keymap, (size_t) mapLen); str += mapLen; } *str++ = codesLen; if (codesLen > 0) { - memcpy(str, names->keycodes, codesLen); + memcpy(str, names->keycodes, (size_t) codesLen); str += codesLen; } *str++ = typesLen; if (typesLen > 0) { - memcpy(str, names->types, typesLen); + memcpy(str, names->types, (size_t) typesLen); str += typesLen; } *str++ = compatLen; if (compatLen > 0) { - memcpy(str, names->compat, compatLen); + memcpy(str, names->compat, (size_t) compatLen); str += compatLen; } *str++ = symsLen; if (symsLen > 0) { - memcpy(str, names->symbols, symsLen); + memcpy(str, names->symbols, (size_t) symsLen); str += symsLen; } *str++ = geomLen; if (geomLen > 0) { - memcpy(str, names->geometry, geomLen); + memcpy(str, names->geometry, (size_t) geomLen); str += geomLen; } if ((!_XReply(dpy, (xReply *) &rep, 0, xFalse)) || (!rep.reported)) diff --git a/nx-X11/lib/src/xkb/XKBGetMap.c b/nx-X11/lib/src/xkb/XKBGetMap.c index 6e3c74343..2a28e1b27 100644 --- a/nx-X11/lib/src/xkb/XKBGetMap.c +++ b/nx-X11/lib/src/xkb/XKBGetMap.c @@ -63,12 +63,9 @@ _XkbReadKeyTypes(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep) if (desc->nMapEntries > 0) { if ((type->map == NULL) || (desc->nMapEntries > type->map_count)) { - XkbKTMapEntryRec *prev_map = type->map; - - type->map = _XkbTypedRealloc(type->map, desc->nMapEntries, - XkbKTMapEntryRec); + _XkbResizeArray(type->map, type->map_count, + desc->nMapEntries, XkbKTMapEntryRec); if (type->map == NULL) { - _XkbFree(prev_map); return BadAlloc; } } @@ -81,13 +78,9 @@ _XkbReadKeyTypes(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep) if (desc->preserve && (desc->nMapEntries > 0)) { if ((!type->preserve) || (desc->nMapEntries > lastMapCount)) { - XkbModsRec *prev_preserve = type->preserve; - - type->preserve = _XkbTypedRealloc(type->preserve, - desc->nMapEntries, - XkbModsRec); + _XkbResizeArray(type->preserve, lastMapCount, + desc->nMapEntries, XkbModsRec); if (type->preserve == NULL) { - _XkbFree(prev_preserve); return BadAlloc; } } @@ -188,12 +181,10 @@ _XkbReadKeySyms(XkbReadBufferPtr buf, XkbDescPtr xkb, xkbGetMapReply *rep) oldMap->offset = offset; if (offset + newMap->nSyms >= map->size_syms) { register int sz; - KeySym *prev_syms = map->syms; sz = map->size_syms + 128; - map->syms = _XkbTypedRealloc(map->syms, sz, KeySym); + _XkbResizeArray(map->syms, map->size_syms, sz, KeySym); if (map->syms == NULL) { - _XkbFree(prev_syms); map->size_syms = 0; return BadAlloc; } @@ -261,7 +252,7 @@ _XkbReadKeyActions(XkbReadBufferPtr buf, XkbDescPtr info, xkbGetMapReply *rep) if (nKeyActs < sizeof numDescBuf) numDesc = numDescBuf; else - numDesc = Xmalloc(nKeyActs * sizeof(CARD8)); + numDesc = Xmallocarray(nKeyActs, sizeof(CARD8)); if (!_XkbCopyFromReadBuffer(buf, (char *) numDesc, nKeyActs)) { ret = BadLength; diff --git a/nx-X11/lib/src/xkb/XKBList.c b/nx-X11/lib/src/xkb/XKBList.c index d3d29e2a6..ea61250a0 100644 --- a/nx-X11/lib/src/xkb/XKBList.c +++ b/nx-X11/lib/src/xkb/XKBList.c @@ -82,7 +82,7 @@ _ReadListing(XkbReadBufferPtr buf, int count, Status * status_rtrn) str = (char *) _XkbGetReadBufferPtr(buf, wlen); if (!str) goto BAILOUT; - memcpy(this->name, str, slen); + memcpy(this->name, str, (size_t) slen); } return first; BAILOUT: @@ -154,32 +154,32 @@ XkbListComponents(Display *dpy, *str++ = mapLen; if (mapLen > 0) { - memcpy(str, ptrns->keymap, mapLen); + memcpy(str, ptrns->keymap, (size_t) mapLen); str += mapLen; } *str++ = codesLen; if (codesLen > 0) { - memcpy(str, ptrns->keycodes, codesLen); + memcpy(str, ptrns->keycodes, (size_t) codesLen); str += codesLen; } *str++ = typesLen; if (typesLen > 0) { - memcpy(str, ptrns->types, typesLen); + memcpy(str, ptrns->types, (size_t) typesLen); str += typesLen; } *str++ = compatLen; if (compatLen > 0) { - memcpy(str, ptrns->compat, compatLen); + memcpy(str, ptrns->compat, (size_t) compatLen); str += compatLen; } *str++ = symsLen; if (symsLen > 0) { - memcpy(str, ptrns->symbols, symsLen); + memcpy(str, ptrns->symbols, (size_t) symsLen); str += symsLen; } *str++ = geomLen; if (geomLen > 0) { - memcpy(str, ptrns->geometry, geomLen); + memcpy(str, ptrns->geometry, (size_t) geomLen); str += geomLen; } if (!_XReply(dpy, (xReply *) &rep, 0, xFalse)) diff --git a/nx-X11/lib/src/xkb/XKBMAlloc.c b/nx-X11/lib/src/xkb/XKBMAlloc.c index 2467a2024..fdfd54bab 100644 --- a/nx-X11/lib/src/xkb/XKBMAlloc.c +++ b/nx-X11/lib/src/xkb/XKBMAlloc.c @@ -69,25 +69,17 @@ XkbAllocClientMap(XkbDescPtr xkb, unsigned which, unsigned nTotalTypes) if ((which & XkbKeyTypesMask) && (nTotalTypes > 0)) { if (map->types == NULL) { - map->types = _XkbTypedCalloc(nTotalTypes, XkbKeyTypeRec); - if (map->types == NULL) - return BadAlloc; - map->num_types = 0; - map->size_types = nTotalTypes; + map->num_types = map->size_types = 0; } - else if (map->size_types < nTotalTypes) { - XkbKeyTypeRec *prev_types = map->types; + if ((map->types == NULL) || (map->size_types < nTotalTypes)) { + _XkbResizeArray(map->types, map->size_types, nTotalTypes, + XkbKeyTypeRec); - map->types = - _XkbTypedRealloc(map->types, nTotalTypes, XkbKeyTypeRec); if (map->types == NULL) { - _XkbFree(prev_types); map->num_types = map->size_types = 0; return BadAlloc; } map->size_types = nTotalTypes; - bzero(&map->types[map->num_types], - ((map->size_types - map->num_types) * sizeof(XkbKeyTypeRec))); } } if (which & XkbKeySymsMask) { @@ -164,26 +156,20 @@ XkbAllocServerMap(XkbDescPtr xkb, unsigned which, unsigned nNewActions) if (nNewActions < 1) nNewActions = 1; if (map->acts == NULL) { - map->acts = _XkbTypedCalloc((nNewActions + 1), XkbAction); - if (map->acts == NULL) - return BadAlloc; map->num_acts = 1; - map->size_acts = nNewActions + 1; + map->size_acts = 0; } - else if ((map->size_acts - map->num_acts) < nNewActions) { + if ((map->acts == NULL) || + ((map->size_acts - map->num_acts) < nNewActions)) { unsigned need; - XkbAction *prev_acts = map->acts; need = map->num_acts + nNewActions; - map->acts = _XkbTypedRealloc(map->acts, need, XkbAction); + _XkbResizeArray(map->acts, map->size_acts, need, XkbAction); if (map->acts == NULL) { - _XkbFree(prev_acts); map->num_acts = map->size_acts = 0; return BadAlloc; } map->size_acts = need; - bzero(&map->acts[map->num_acts], - ((map->size_acts - map->num_acts) * sizeof(XkbAction))); } if (map->key_acts == NULL) { i = xkb->max_key_code + 1; @@ -390,24 +376,18 @@ XkbResizeKeyType(XkbDescPtr xkb, type->map_count = 0; } else { - XkbKTMapEntryRec *prev_map = type->map; - if ((map_count > type->map_count) || (type->map == NULL)) - type->map = - _XkbTypedRealloc(type->map, map_count, XkbKTMapEntryRec); + _XkbResizeArray(type->map, type->map_count, map_count, + XkbKTMapEntryRec); if (!type->map) { - _XkbFree(prev_map); return BadAlloc; } if (want_preserve) { - XkbModsRec *prev_preserve = type->preserve; - if ((map_count > type->map_count) || (type->preserve == NULL)) { - type->preserve = _XkbTypedRealloc(type->preserve, map_count, - XkbModsRec); + _XkbResizeArray(type->preserve, type->map_count, map_count, + XkbModsRec); } if (!type->preserve) { - _XkbFree(prev_preserve); return BadAlloc; } } @@ -419,12 +399,8 @@ XkbResizeKeyType(XkbDescPtr xkb, } if ((new_num_lvls > type->num_levels) || (type->level_names == NULL)) { - Atom *prev_level_names = type->level_names; - - type->level_names = - _XkbTypedRealloc(type->level_names, new_num_lvls, Atom); + _XkbResizeArray(type->level_names, type->num_levels, new_num_lvls, Atom); if (!type->level_names) { - _XkbFree(prev_level_names); return BadAlloc; } } @@ -705,7 +681,7 @@ XkbChangeKeycodeRange(XkbDescPtr xkb, if (changes) { changes->map.changed = _ExtendRange(changes->map.changed, XkbVirtualModMapMask, minKC, - &changes->map.first_modmap_key, + &changes->map.first_vmodmap_key, &changes->map.num_vmodmap_keys); } } @@ -728,21 +704,11 @@ XkbChangeKeycodeRange(XkbDescPtr xkb, tmp = maxKC - xkb->max_key_code; if (xkb->map) { if (xkb->map->key_sym_map) { - XkbSymMapRec *prev_key_sym_map = xkb->map->key_sym_map; - - xkb->map->key_sym_map = _XkbTypedRealloc(xkb->map->key_sym_map, - (maxKC + 1), XkbSymMapRec); + _XkbResizeArray(xkb->map->key_sym_map, xkb->max_key_code + 1, + (maxKC + 1), XkbSymMapRec); if (!xkb->map->key_sym_map) { - _XkbFree(prev_key_sym_map); return BadAlloc; } -#ifdef NXAGENT_SERVER - bzero((char *) &xkb->map->key_sym_map[xkb->max_key_code + 1], - tmp * sizeof(XkbSymMapRec)); -#else - bzero((char *) &xkb->map->key_sym_map[xkb->max_key_code], - tmp * sizeof(XkbSymMapRec)); -#endif if (changes) { changes->map.changed = _ExtendRange(changes->map.changed, XkbKeySymsMask, maxKC, @@ -751,19 +717,11 @@ XkbChangeKeycodeRange(XkbDescPtr xkb, } } if (xkb->map->modmap) { - unsigned char *prev_modmap = xkb->map->modmap; - - xkb->map->modmap = _XkbTypedRealloc(xkb->map->modmap, - (maxKC + 1), unsigned char); + _XkbResizeArray(xkb->map->modmap, xkb->max_key_code + 1, + (maxKC + 1), unsigned char); if (!xkb->map->modmap) { - _XkbFree(prev_modmap); return BadAlloc; } -#ifdef NXAGENT_SERVER - bzero((char *) &xkb->map->modmap[xkb->max_key_code + 1], tmp); -#else - bzero((char *) &xkb->map->modmap[xkb->max_key_code], tmp); -#endif if (changes) { changes->map.changed = _ExtendRange(changes->map.changed, XkbModifierMapMask, maxKC, @@ -774,22 +732,11 @@ XkbChangeKeycodeRange(XkbDescPtr xkb, } if (xkb->server) { if (xkb->server->behaviors) { - XkbBehavior *prev_behaviors = xkb->server->behaviors; - - xkb->server->behaviors = - _XkbTypedRealloc(xkb->server->behaviors, (maxKC + 1), - XkbBehavior); + _XkbResizeArray(xkb->server->behaviors, xkb->max_key_code + 1, + (maxKC + 1), XkbBehavior); if (!xkb->server->behaviors) { - _XkbFree(prev_behaviors); return BadAlloc; } -#ifdef NXAGENT_SERVER - bzero((char *) &xkb->server->behaviors[xkb->max_key_code + 1], - tmp * sizeof(XkbBehavior)); -#else - bzero((char *) &xkb->server->behaviors[xkb->max_key_code], - tmp * sizeof(XkbBehavior)); -#endif if (changes) { changes->map.changed = _ExtendRange(changes->map.changed, XkbKeyBehaviorsMask, maxKC, @@ -798,21 +745,11 @@ XkbChangeKeycodeRange(XkbDescPtr xkb, } } if (xkb->server->key_acts) { - unsigned short *prev_key_acts = xkb->server->key_acts; - - xkb->server->key_acts = _XkbTypedRealloc(xkb->server->key_acts, - (maxKC + 1), unsigned short); + _XkbResizeArray(xkb->server->key_acts, xkb->max_key_code + 1, + (maxKC + 1), unsigned short); if (!xkb->server->key_acts) { - _XkbFree(prev_key_acts); return BadAlloc; } -#ifdef NXAGENT_SERVER - bzero((char *) &xkb->server->key_acts[xkb->max_key_code + 1], - tmp * sizeof(unsigned short)); -#else - bzero((char *) &xkb->server->key_acts[xkb->max_key_code], - tmp * sizeof(unsigned short)); -#endif if (changes) { changes->map.changed = _ExtendRange(changes->map.changed, XkbKeyActionsMask, maxKC, @@ -821,45 +758,25 @@ XkbChangeKeycodeRange(XkbDescPtr xkb, } } if (xkb->server->vmodmap) { - unsigned short *prev_vmodmap = xkb->server->vmodmap; - - xkb->server->vmodmap = _XkbTypedRealloc(xkb->server->vmodmap, - (maxKC + 1), unsigned short); + _XkbResizeArray(xkb->server->vmodmap, xkb->max_key_code + 1, + (maxKC + 1), unsigned short); if (!xkb->server->vmodmap) { - _XkbFree(prev_vmodmap); return BadAlloc; } -#ifdef NXAGENT_SERVER - bzero((char *) &xkb->server->vmodmap[xkb->max_key_code + 1], - tmp * sizeof(unsigned short)); -#else - bzero((char *) &xkb->server->vmodmap[xkb->max_key_code], - tmp * sizeof(unsigned short)); -#endif if (changes) { changes->map.changed = _ExtendRange(changes->map.changed, XkbVirtualModMapMask, maxKC, - &changes->map.first_modmap_key, + &changes->map.first_vmodmap_key, &changes->map.num_vmodmap_keys); } } } if ((xkb->names) && (xkb->names->keys)) { - XkbKeyNameRec *prev_keys = xkb->names->keys; - - xkb->names->keys = _XkbTypedRealloc(xkb->names->keys, - (maxKC + 1), XkbKeyNameRec); + _XkbResizeArray(xkb->names->keys, xkb->max_key_code + 1, + (maxKC + 1), XkbKeyNameRec); if (!xkb->names->keys) { - _XkbFree(prev_keys); return BadAlloc; } -#ifdef NXAGENT_SERVER - bzero((char *) &xkb->names->keys[xkb->max_key_code + 1], - tmp * sizeof(XkbKeyNameRec)); -#else - bzero((char *) &xkb->names->keys[xkb->max_key_code], - tmp * sizeof(XkbKeyNameRec)); -#endif if (changes) { changes->names.changed = _ExtendRange(changes->names.changed, XkbKeyNamesMask, maxKC, diff --git a/nx-X11/lib/src/xkb/XKBMisc.c b/nx-X11/lib/src/xkb/XKBMisc.c index ab48b6124..0baf6f061 100644 --- a/nx-X11/lib/src/xkb/XKBMisc.c +++ b/nx-X11/lib/src/xkb/XKBMisc.c @@ -735,7 +735,7 @@ XkbChangeTypesOfKey(XkbDescPtr xkb, return BadAlloc; } pSyms = XkbKeySymsPtr(xkb, key); - memcpy(oldSyms, pSyms, XkbKeyNumSyms(xkb, key) * sizeof(KeySym)); + memcpy(oldSyms, pSyms, (size_t) XkbKeyNumSyms(xkb, key) * sizeof(KeySym)); pSyms = XkbResizeKeySyms(xkb, key, width * nGroups); if (pSyms == NULL) return BadAlloc; @@ -754,7 +754,7 @@ XkbChangeTypesOfKey(XkbDescPtr xkb, XkbAction oldActs[XkbMaxSymsPerKey], *pActs; pActs = XkbKeyActionsPtr(xkb, key); - memcpy(oldActs, pActs, XkbKeyNumSyms(xkb, key) * sizeof(XkbAction)); + memcpy(oldActs, pActs, (size_t) XkbKeyNumSyms(xkb, key) * sizeof(XkbAction)); pActs = XkbResizeKeyActions(xkb, key, width * nGroups); if (pActs == NULL) return BadAlloc; @@ -857,7 +857,7 @@ XkbUpdateKeyTypeVirtualMods(XkbDescPtr xkb, XkbChangesPtr changes) { register unsigned int i; - unsigned int mask = 0; + unsigned int mask; XkbVirtualModsToReal(xkb, type->mods.vmods, &mask); type->mods.mask = type->mods.real_mods | mask; @@ -919,7 +919,7 @@ XkbApplyVirtualModChanges(XkbDescPtr xkb, changes); } if (changed & xkb->ctrls->internal.vmods) { - unsigned int newMask = 0; + unsigned int newMask; XkbVirtualModsToReal(xkb, xkb->ctrls->internal.vmods, &newMask); newMask |= xkb->ctrls->internal.real_mods; @@ -932,7 +932,7 @@ XkbApplyVirtualModChanges(XkbDescPtr xkb, } } if (changed & xkb->ctrls->ignore_lock.vmods) { - unsigned int newMask = 0; + unsigned int newMask; XkbVirtualModsToReal(xkb, xkb->ctrls->ignore_lock.vmods, &newMask); newMask |= xkb->ctrls->ignore_lock.real_mods; @@ -950,7 +950,7 @@ XkbApplyVirtualModChanges(XkbDescPtr xkb, map = &xkb->indicators->maps[0]; for (i = 0; i < XkbNumIndicators; i++, map++) { if (map->mods.vmods & changed) { - unsigned int newMask = 0; + unsigned int newMask; XkbVirtualModsToReal(xkb, map->mods.vmods, &newMask); newMask |= map->mods.real_mods; @@ -969,7 +969,7 @@ XkbApplyVirtualModChanges(XkbDescPtr xkb, compat = xkb->compat; for (i = 0; i < XkbNumKbdGroups; i++) { - unsigned int newMask = 0; + unsigned int newMask; XkbVirtualModsToReal(xkb, compat->groups[i].vmods, &newMask); newMask |= compat->groups[i].real_mods; diff --git a/nx-X11/lib/src/xkb/XKBNames.c b/nx-X11/lib/src/xkb/XKBNames.c index 951fd1da8..c14329203 100644 --- a/nx-X11/lib/src/xkb/XKBNames.c +++ b/nx-X11/lib/src/xkb/XKBNames.c @@ -205,14 +205,14 @@ _XkbReadGetNamesReply(Display *dpy, if (rep->nRadioGroups > 0) { Atom *rgNames; - if (names->radio_groups == NULL) - names->radio_groups = _XkbTypedCalloc(rep->nRadioGroups, Atom); - else if (names->num_rg < rep->nRadioGroups) { - names->radio_groups = _XkbTypedRealloc(names->radio_groups, - rep->nRadioGroups, Atom); + if ((names->radio_groups == NULL) || + (names->num_rg < rep->nRadioGroups)) { + _XkbResizeArray(names->radio_groups, names->num_rg, + rep->nRadioGroups, Atom); } rgNames = names->radio_groups; if (!rgNames) { + names->num_rg = 0; goto BAILOUT; } if (!_XkbReadBufferCopy32 diff --git a/nx-X11/lib/src/xkb/XKBRdBuf.c b/nx-X11/lib/src/xkb/XKBRdBuf.c index 381f4c900..a34039f37 100644 --- a/nx-X11/lib/src/xkb/XKBRdBuf.c +++ b/nx-X11/lib/src/xkb/XKBRdBuf.c @@ -71,7 +71,7 @@ _XkbCopyFromReadBuffer(XkbReadBufferPtr from, char *to, int size) if ((from == NULL) || (from->error) || (to == NULL) || (size < 1) || (_XkbReadBufferDataLeft(from) < size)) return 0; - memcpy(to, from->data, size); + memcpy(to, from->data, (size_t)size); from->data += size; return 1; } diff --git a/nx-X11/lib/src/xkb/XKBSetGeom.c b/nx-X11/lib/src/xkb/XKBSetGeom.c index ee254e0dc..5d94072ce 100644 --- a/nx-X11/lib/src/xkb/XKBSetGeom.c +++ b/nx-X11/lib/src/xkb/XKBSetGeom.c @@ -52,7 +52,7 @@ _WriteCountedString(char *wire, char *str) { CARD16 len, *pLen; - len = (str ? strlen(str) : 0); + len = (CARD16) (str ? strlen(str) : 0); pLen = (CARD16 *) wire; *pLen = len; if (len && str) @@ -69,8 +69,8 @@ _SizeGeomProperties(XkbGeometryPtr geom) for (size = i = 0, prop = geom->properties; i < geom->num_properties; i++, prop++) { - size += _SizeCountedString(prop->name); - size += _SizeCountedString(prop->value); + size = (int) ((unsigned) size + _SizeCountedString(prop->name)); + size = (int) ((unsigned) size + _SizeCountedString(prop->value)); } return size; } @@ -82,7 +82,7 @@ _SizeGeomColors(XkbGeometryPtr geom) register XkbColorPtr color; for (i = size = 0, color = geom->colors; i < geom->num_colors; i++, color++) { - size += _SizeCountedString(color->spec); + size = (int) ((unsigned) size + _SizeCountedString(color->spec)); } return size; } @@ -114,11 +114,11 @@ _SizeGeomDoodads(int num_doodads, XkbDoodadPtr doodad) for (i = size = 0; i < num_doodads; i++, doodad++) { size += SIZEOF(xkbAnyDoodadWireDesc); if (doodad->any.type == XkbTextDoodad) { - size += _SizeCountedString(doodad->text.text); - size += _SizeCountedString(doodad->text.font); + size = (int) ((unsigned) size + _SizeCountedString(doodad->text.text)); + size = (int) ((unsigned) size + _SizeCountedString(doodad->text.font)); } else if (doodad->any.type == XkbLogoDoodad) { - size += _SizeCountedString(doodad->logo.logo_name); + size = (int) ((unsigned) size + _SizeCountedString(doodad->logo.logo_name)); } } return size; @@ -389,7 +389,7 @@ _WriteGeomKeyAliases(char *wire, XkbGeometryPtr geom) sz = geom->num_key_aliases * (XkbKeyNameLength * 2); if (sz > 0) { - memcpy(wire, (char *) geom->key_aliases, sz); + memcpy(wire, (char *) geom->key_aliases, (size_t)sz); wire += sz; } return wire; @@ -404,7 +404,7 @@ _SendSetGeometry(Display *dpy, XkbGeometryPtr geom, xkbSetGeometryReq *req) char *wire, *tbuf; sz = 0; - sz += _SizeCountedString(geom->label_font); + sz = (int) ((unsigned) (sz + _SizeCountedString(geom->label_font))); sz += _SizeGeomProperties(geom); sz += _SizeGeomColors(geom); sz += _SizeGeomShapes(geom); diff --git a/nx-X11/lib/src/xkb/XKBlibint.h b/nx-X11/lib/src/xkb/XKBlibint.h index dad48b703..0b9a096b4 100644 --- a/nx-X11/lib/src/xkb/XKBlibint.h +++ b/nx-X11/lib/src/xkb/XKBlibint.h @@ -29,6 +29,7 @@ THE USE OR PERFORMANCE OF THIS SOFTWARE. #include <nx-X11/Xutil.h> #include <nx-X11/XKBlib.h> +#include "reallocarray.h" #define XkbMapPending (1<<0) #define XkbXlibNewKeyboard (1<<1) @@ -119,11 +120,26 @@ typedef struct _XkbReadBuffer { #define _XkbRealloc(o,s) Xrealloc((o),(s)) #define _XkbTypedAlloc(t) ((t *)Xmalloc(sizeof(t))) #define _XkbTypedCalloc(n,t) ((t *)Xcalloc((n),sizeof(t))) -#define _XkbTypedRealloc(o,n,t) \ - ((o) ? (t *)Xrealloc((o), (n)*sizeof(t)) : _XkbTypedCalloc(n,t)) -#define _XkbClearElems(a,f,l,t) bzero(&(a)[f], ((l)-(f)+1) * sizeof(t)) #define _XkbFree(p) Xfree(p) +/* Resizes array to hold new_num elements, zeroing newly added entries. + Destroys old array on failure. */ +#define _XkbResizeArray(array, old_num, new_num, type) \ + do { \ + if (array == NULL) { \ + array = _XkbTypedCalloc(new_num, type); \ + } else { \ + type *prev_array = array; \ + array = Xreallocarray(array, new_num, sizeof(type)); \ + if (_X_UNLIKELY((array) == NULL)) { \ + _XkbFree(prev_array); \ + } else if ((new_num) > (old_num)) { \ + bzero(&array[old_num], \ + ((new_num) - (old_num)) * sizeof(type)); \ + } \ + } \ + } while(0) + _XFUNCPROTOBEGIN extern void _XkbReloadDpy( |