Commit 4fe6b03b authored by Alan Coopersmith's avatar Alan Coopersmith

Convert XKB to new *allocarray functions

Signed-off-by: 's avatarAlan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: 's avatarMatt Turner <mattst88@gmail.com>
Acked-by: 's avatarDaniel Stone <daniels@collabora.com>
parent 1c56ac63
......@@ -56,8 +56,8 @@ XkbAllocCompatMap(XkbDescPtr xkb, unsigned which, unsigned nSI)
if (compat->sym_interpret == NULL)
compat->num_si = 0;
prev_interpret = compat->sym_interpret;
compat->sym_interpret = realloc(compat->sym_interpret,
nSI * sizeof(XkbSymInterpretRec));
compat->sym_interpret = reallocarray(compat->sym_interpret,
nSI, sizeof(XkbSymInterpretRec));
if (compat->sym_interpret == NULL) {
free(prev_interpret);
compat->size_si = compat->num_si = 0;
......@@ -159,9 +159,9 @@ XkbAllocNames(XkbDescPtr xkb, unsigned which, int nTotalRG, int nTotalAliases)
else if (nTotalAliases > names->num_key_aliases) {
XkbKeyAliasRec *prev_aliases = names->key_aliases;
names->key_aliases = realloc(names->key_aliases,
nTotalAliases *
sizeof(XkbKeyAliasRec));
names->key_aliases = reallocarray(names->key_aliases,
nTotalAliases,
sizeof(XkbKeyAliasRec));
if (names->key_aliases != NULL) {
memset(&names->key_aliases[names->num_key_aliases], 0,
(nTotalAliases -
......@@ -184,8 +184,8 @@ XkbAllocNames(XkbDescPtr xkb, unsigned which, int nTotalRG, int nTotalAliases)
else if (nTotalRG > names->num_rg) {
Atom *prev_radio_groups = names->radio_groups;
names->radio_groups = realloc(names->radio_groups,
nTotalRG * sizeof(Atom));
names->radio_groups = reallocarray(names->radio_groups,
nTotalRG, sizeof(Atom));
if (names->radio_groups != NULL) {
memset(&names->radio_groups[names->num_rg], 0,
(nTotalRG - names->num_rg) * sizeof(Atom));
......
......@@ -409,7 +409,7 @@ XkbGeomRealloc(void **buffer, int szItems, int nrItems,
return FALSE;
/* Check if there is need to resize. */
if (nrItems != szItems)
if (!(items = realloc(items, nrItems * itemSize)))
if (!(items = reallocarray(items, nrItems, itemSize)))
return FALSE;
/* Clear specified items to zero. */
switch (clearance) {
......
......@@ -80,7 +80,7 @@ XkbAllocClientMap(XkbDescPtr xkb, unsigned which, unsigned nTotalTypes)
XkbKeyTypeRec *prev_types = map->types;
map->types =
realloc(map->types, nTotalTypes * sizeof(XkbKeyTypeRec));
reallocarray(map->types, nTotalTypes, sizeof(XkbKeyTypeRec));
if (map->types == NULL) {
free(prev_types);
map->num_types = map->size_types = 0;
......@@ -177,7 +177,7 @@ XkbAllocServerMap(XkbDescPtr xkb, unsigned which, unsigned nNewActions)
XkbAction *prev_acts = map->acts;
need = map->num_acts + nNewActions;
map->acts = realloc(map->acts, need * sizeof(XkbAction));
map->acts = reallocarray(map->acts, need, sizeof(XkbAction));
if (map->acts == NULL) {
free(prev_acts);
map->num_acts = map->size_acts = 0;
......@@ -309,7 +309,7 @@ XkbResizeKeyType(XkbDescPtr xkb,
if ((map_count > type->map_count) || (type->map == NULL))
type->map =
realloc(type->map, map_count * sizeof(XkbKTMapEntryRec));
reallocarray(type->map, map_count, sizeof(XkbKTMapEntryRec));
if (!type->map) {
free(prev_map);
return BadAlloc;
......@@ -318,8 +318,8 @@ XkbResizeKeyType(XkbDescPtr xkb,
XkbModsRec *prev_preserve = type->preserve;
if ((map_count > type->map_count) || (type->preserve == NULL)) {
type->preserve = realloc(type->preserve,
map_count * sizeof(XkbModsRec));
type->preserve = reallocarray(type->preserve,
map_count, sizeof(XkbModsRec));
}
if (!type->preserve) {
free(prev_preserve);
......@@ -336,8 +336,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 = realloc(type->level_names,
new_num_lvls * sizeof(Atom));
type->level_names = reallocarray(type->level_names,
new_num_lvls, sizeof(Atom));
if (!type->level_names) {
free(prev_level_names);
return BadAlloc;
......@@ -659,9 +659,9 @@ XkbChangeKeycodeRange(XkbDescPtr xkb,
if (xkb->map->key_sym_map) {
XkbSymMapRec *prev_key_sym_map = xkb->map->key_sym_map;
xkb->map->key_sym_map = realloc(xkb->map->key_sym_map,
(maxKC +
1) * sizeof(XkbSymMapRec));
xkb->map->key_sym_map = reallocarray(xkb->map->key_sym_map,
maxKC + 1,
sizeof(XkbSymMapRec));
if (!xkb->map->key_sym_map) {
free(prev_key_sym_map);
return BadAlloc;
......@@ -680,8 +680,9 @@ XkbChangeKeycodeRange(XkbDescPtr xkb,
if (xkb->map->modmap) {
unsigned char *prev_modmap = xkb->map->modmap;
xkb->map->modmap = realloc(xkb->map->modmap,
(maxKC + 1) * sizeof(unsigned char));
xkb->map->modmap = reallocarray(xkb->map->modmap,
maxKC + 1,
sizeof(unsigned char));
if (!xkb->map->modmap) {
free(prev_modmap);
return BadAlloc;
......@@ -702,9 +703,9 @@ XkbChangeKeycodeRange(XkbDescPtr xkb,
if (xkb->server->behaviors) {
XkbBehavior *prev_behaviors = xkb->server->behaviors;
xkb->server->behaviors = realloc(xkb->server->behaviors,
(maxKC +
1) * sizeof(XkbBehavior));
xkb->server->behaviors = reallocarray(xkb->server->behaviors,
maxKC + 1,
sizeof(XkbBehavior));
if (!xkb->server->behaviors) {
free(prev_behaviors);
return BadAlloc;
......@@ -724,9 +725,9 @@ XkbChangeKeycodeRange(XkbDescPtr xkb,
if (xkb->server->key_acts) {
unsigned short *prev_key_acts = xkb->server->key_acts;
xkb->server->key_acts = realloc(xkb->server->key_acts,
(maxKC +
1) * sizeof(unsigned short));
xkb->server->key_acts = reallocarray(xkb->server->key_acts,
maxKC + 1,
sizeof(unsigned short));
if (!xkb->server->key_acts) {
free(prev_key_acts);
return BadAlloc;
......@@ -746,9 +747,9 @@ XkbChangeKeycodeRange(XkbDescPtr xkb,
if (xkb->server->vmodmap) {
unsigned short *prev_vmodmap = xkb->server->vmodmap;
xkb->server->vmodmap = realloc(xkb->server->vmodmap,
(maxKC +
1) * sizeof(unsigned short));
xkb->server->vmodmap = reallocarray(xkb->server->vmodmap,
maxKC + 1,
sizeof(unsigned short));
if (!xkb->server->vmodmap) {
free(prev_vmodmap);
return BadAlloc;
......@@ -769,8 +770,8 @@ XkbChangeKeycodeRange(XkbDescPtr xkb,
if ((xkb->names) && (xkb->names->keys)) {
XkbKeyNameRec *prev_keys = xkb->names->keys;
xkb->names->keys = realloc(xkb->names->keys,
(maxKC + 1) * sizeof(XkbKeyNameRec));
xkb->names->keys = reallocarray(xkb->names->keys,
maxKC + 1, sizeof(XkbKeyNameRec));
if (!xkb->names->keys) {
free(prev_keys);
return BadAlloc;
......
......@@ -89,11 +89,11 @@ InputLineAddChar(InputLine * line, int ch)
{
if (line->num_line >= line->sz_line) {
if (line->line == line->buf) {
line->line = malloc(line->sz_line * 2);
line->line = xallocarray(line->sz_line, 2);
memcpy(line->line, line->buf, line->sz_line);
}
else {
line->line = realloc((char *) line->line, line->sz_line * 2);
line->line = reallocarray(line->line, line->sz_line, 2);
}
line->sz_line *= 2;
}
......@@ -897,8 +897,8 @@ XkbRF_AddRule(XkbRF_RulesPtr rules)
}
else if (rules->num_rules >= rules->sz_rules) {
rules->sz_rules *= 2;
rules->rules = realloc(rules->rules,
rules->sz_rules * sizeof(XkbRF_RuleRec));
rules->rules = reallocarray(rules->rules,
rules->sz_rules, sizeof(XkbRF_RuleRec));
}
if (!rules->rules) {
rules->sz_rules = rules->num_rules = 0;
......@@ -919,8 +919,8 @@ XkbRF_AddGroup(XkbRF_RulesPtr rules)
}
else if (rules->num_groups >= rules->sz_groups) {
rules->sz_groups *= 2;
rules->groups = realloc(rules->groups,
rules->sz_groups * sizeof(XkbRF_GroupRec));
rules->groups = reallocarray(rules->groups,
rules->sz_groups, sizeof(XkbRF_GroupRec));
}
if (!rules->groups) {
rules->sz_groups = rules->num_groups = 0;
......
......@@ -2216,12 +2216,11 @@ SetKeyBehaviors(XkbSrvInfoPtr xkbi,
}
if (maxRG > (int) xkbi->nRadioGroups) {
int sz = maxRG * sizeof(XkbRadioGroupRec);
if (xkbi->radioGroups)
xkbi->radioGroups = realloc(xkbi->radioGroups, sz);
xkbi->radioGroups = reallocarray(xkbi->radioGroups, maxRG,
sizeof(XkbRadioGroupRec));
else
xkbi->radioGroups = calloc(1, sz);
xkbi->radioGroups = calloc(maxRG, sizeof(XkbRadioGroupRec));
if (xkbi->radioGroups) {
if (xkbi->nRadioGroups)
memset(&xkbi->radioGroups[xkbi->nRadioGroups], 0,
......@@ -2700,15 +2699,16 @@ XkbSendCompatMap(ClientPtr client,
char *data;
int size;
size = rep->length * 4;
if (size > 0) {
data = malloc(size);
if (rep->length > 0) {
data = xallocarray(rep->length, 4);
if (data) {
register unsigned i, bit;
xkbModsWireDesc *grp;
XkbSymInterpretPtr sym = &compat->sym_interpret[rep->firstSI];
xkbSymInterpretWireDesc *wire = (xkbSymInterpretWireDesc *) data;
size = rep->length * 4;
for (i = 0; i < rep->nSI; i++, sym++, wire++) {
wire->sym = sym->sym;
wire->mods = sym->mods;
......@@ -2856,9 +2856,9 @@ _XkbSetCompatMap(ClientPtr client, DeviceIntPtr dev,
if ((unsigned) (req->firstSI + req->nSI) > compat->num_si) {
compat->num_si = req->firstSI + req->nSI;
compat->sym_interpret = realloc(compat->sym_interpret,
compat->num_si *
sizeof(XkbSymInterpretRec));
compat->sym_interpret = reallocarray(compat->sym_interpret,
compat->num_si,
sizeof(XkbSymInterpretRec));
if (!compat->sym_interpret) {
compat->num_si = 0;
return BadAlloc;
......@@ -3086,14 +3086,15 @@ XkbSendIndicatorMap(ClientPtr client,
register int i;
register unsigned bit;
length = rep->length * 4;
if (length > 0) {
if (rep->length > 0) {
CARD8 *to;
to = map = malloc(length);
to = map = xallocarray(rep->length, 4);
if (map) {
xkbIndicatorMapWireDesc *wire = (xkbIndicatorMapWireDesc *) to;
length = rep->length * 4;
for (i = 0, bit = 1; i < XkbNumIndicators; i++, bit <<= 1) {
if (rep->which & bit) {
wire->flags = indicators->maps[i].flags;
......@@ -4863,7 +4864,6 @@ XkbComputeGetGeometryReplySize(XkbGeometryPtr geom,
}
return Success;
}
static int
XkbSendGeometry(ClientPtr client,
XkbGeometryPtr geom, xkbGetGeometryReply * rep, Bool freeGeom)
......@@ -4872,10 +4872,10 @@ XkbSendGeometry(ClientPtr client,
int len;
if (geom != NULL) {
len = rep->length * 4;
start = desc = malloc(len);
start = desc = xallocarray(rep->length, 4);
if (!start)
return BadAlloc;
len = rep->length * 4;
desc = XkbWriteCountedString(desc, geom->label_font, client->swapped);
if (rep->nProperties > 0)
desc = XkbWriteGeomProperties(desc, geom, client->swapped);
......
......@@ -1103,8 +1103,8 @@ _XkbNextFreeFilter(XkbSrvInfoPtr xkbi)
}
}
xkbi->szFilters *= 2;
xkbi->filters = realloc(xkbi->filters,
xkbi->szFilters * sizeof(XkbFilterRec));
xkbi->filters = reallocarray(xkbi->filters,
xkbi->szFilters, sizeof(XkbFilterRec));
/* 6/21/93 (ef) -- XXX! deal with allocation failure */
memset(&xkbi->filters[xkbi->szFilters / 2], 0,
(xkbi->szFilters / 2) * sizeof(XkbFilterRec));
......
This diff is collapsed.
......@@ -64,7 +64,7 @@ XkmInsureSize(void *oldPtr, int oldCount, int *newCountRtrn, int elemSize)
oldPtr = calloc(newCount, elemSize);
}
else if (oldCount < newCount) {
oldPtr = realloc(oldPtr, newCount * elemSize);
oldPtr = reallocarray(oldPtr, newCount, elemSize);
if (oldPtr != NULL) {
char *tmp = (char *) oldPtr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment