summaryrefslogtreecommitdiff
path: root/xkb/xkbUtils.c
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2008-02-16 19:57:37 +0200
committerDaniel Stone <daniel@fooishbar.org>2008-02-17 22:52:07 +0200
commit2d256f098ae05033ad76672d5ebdb9dfa7e6b995 (patch)
treefef7a11a34e121483f846fe6f096daa19d8858e6 /xkb/xkbUtils.c
parentab79110a84b2d299ecae0605fa535edbebd99565 (diff)
XKB: Always set size correctly in XkbCopyKeymap's geometry routines
We were forgetting to set the sizes for sections and rows and a couple of other misc bits in XkbCopyKeymap's geometry. Sort that out, and add a couple of clarifying comments along the way.
Diffstat (limited to 'xkb/xkbUtils.c')
-rw-r--r--xkb/xkbUtils.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index 28d66b38b..b3132701d 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -1506,10 +1506,12 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies)
/* properties */
if (src->geom->num_properties) {
if (src->geom->num_properties != dst->geom->sz_properties) {
+ /* If we've got more properties in the destination than
+ * the source, run through and free all the excess ones
+ * first. */
if (src->geom->num_properties < dst->geom->sz_properties) {
for (i = src->geom->num_properties,
- dprop = dst->geom->properties +
- src->geom->num_properties;
+ dprop = dst->geom->properties + i;
i < dst->geom->num_properties;
i++, dprop++) {
xfree(dprop->name);
@@ -1529,6 +1531,8 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies)
dst->geom->properties = tmp;
}
+ /* We don't set num_properties as we need it to try and avoid
+ * too much reallocing. */
dst->geom->sz_properties = src->geom->num_properties;
if (dst->geom->sz_properties > dst->geom->num_properties) {
@@ -1564,6 +1568,7 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies)
}
}
+ /* ... which is already src->geom->num_properties. */
dst->geom->num_properties = dst->geom->sz_properties;
}
else {
@@ -1587,8 +1592,7 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies)
if (src->geom->num_colors != dst->geom->sz_colors) {
if (src->geom->num_colors < dst->geom->sz_colors) {
for (i = src->geom->num_colors,
- dcolor = dst->geom->colors +
- src->geom->num_colors;
+ dcolor = dst->geom->colors + i;
i < dst->geom->num_colors;
i++, dcolor++) {
xfree(dcolor->spec);
@@ -1706,7 +1710,7 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies)
}
doutline->num_points = soutline->num_points;
- doutline->sz_points = soutline->sz_points;
+ doutline->sz_points = soutline->num_points;
}
}
@@ -1785,6 +1789,7 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies)
memset(tmp, 0, src->geom->num_sections * sizeof(XkbSectionRec));
dst->geom->sections = tmp;
dst->geom->num_sections = src->geom->num_sections;
+ dst->geom->sz_sections = src->geom->num_sections;
for (i = 0,
ssection = src->geom->sections,
@@ -1798,6 +1803,8 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool sendNotifies)
dsection->rows = tmp;
}
dsection->num_rows = ssection->num_rows;
+ dsection->sz_rows = ssection->num_rows;
+
for (j = 0, srow = ssection->rows, drow = dsection->rows;
j < ssection->num_rows;
j++, srow++, drow++) {