[PATCH] xkb: when copying the keymap, make sure the structs default to 0/NULL.
Peter Hutterer
mailinglists at who-t.net
Thu Feb 7 04:53:08 PST 2008
Daniel Stone wrote:
> On Thu, Feb 07, 2008 at 08:29:48PM +1030, Peter Hutterer wrote:
> So, geometry has those semantics (having very obviously been written by
> a completely different person than the rest of XKB), but most of it has
> these semantics:
>
> foo->bar = xalloc(6 * sizeof(despair));
> foo->sz_bar = 6;
> foo->num_bar = 0;
>
> if (foo->num_bar) {
> /* picnics ensue, bunnies and koalas live in happy unison */
> }
>
> [...]
>
> if (foo->sz_bar)
> tmp = xrealloc(failure * sizeof(despair)); /* obviously a valid
> pointer if sz_bar is set */
> else
> tmp = xalloc(failure * sizeof(despair));
> if (!tmp)
> /* i've fallen and i can't get up */
>
> foo->bar = tmp;
> foo->sz_bar = failure;
>
> [...]
>
> xfree(foo->bar); /* OH GOD IT BURNS WHY DO YOU HURT ME SO */
> foo->sz_bar = 0; /* i'm so glad we have sz_bar around, not superfluous
> at all */
> foo->num_bar = 0;
>
so I take it the following patch may be a good idea too?
From 9869886864f38dc57dd721aed6ef9c4c51abc69c Mon Sep 17 00:00:00 2001
From: Peter Hutterer <peter at cs.unisa.edu.au>
Date: Thu, 7 Feb 2008 23:14:22 +1030
Subject: [PATCH] xkb: don't use sz_doodad interchangably with num_doodads.
Yes. It hurts my brain too.
---
xkb/xkbUtils.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index 91aee18..db3d0ba 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -1857,7 +1857,7 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool
sendNotifies)
ddoodad->any.type = sdoodad->any.type;
}
dsection->num_doodads = ssection->num_doodads;
- dsection->sz_doodads = ssection->num_doodads;
+ dsection->sz_doodads = ssection->sz_doodads;
}
}
else {
@@ -1911,7 +1911,7 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool
sendNotifies)
memset(tmp, 0, src->geom->num_doodads * sizeof(XkbDoodadRec));
dst->geom->doodads = tmp;
- dst->geom->sz_doodads = src->geom->num_doodads;
+ dst->geom->sz_doodads = src->geom->sz_doodads;
for (i = 0,
sdoodad = src->geom->doodads,
@@ -1932,7 +1932,7 @@ XkbCopyKeymap(XkbDescPtr src, XkbDescPtr dst, Bool
sendNotifies)
}
}
- dst->geom->num_doodads = dst->geom->sz_doodads;
+ dst->geom->num_doodads = dst->geom->num_doodads;
}
else {
if (dst->geom->sz_doodads) {
--
1.5.3
More information about the xorg
mailing list