diff options
author | Peter Hutterer <peter.hutterer@redhat.com> | 2009-05-15 06:21:49 -0400 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@redhat.com> | 2009-05-15 06:24:10 -0400 |
commit | eaf40d1bd1a5737afa5f00c4bc2208fd1562417b (patch) | |
tree | c463e2c0fa98a5d77ac58bd8d9a7785e4ccbca8b /src | |
parent | 04bf8fe62832a38f56041d860a717f13fd3a7295 (diff) |
Remove duplicated code paths in XIGetProperty.
XIGetProperty always returns in the specified format (8, 16, 32) and never in
the Xlib's 64-bit long hackery. So we can clean this code up a bit.
This doesn't affect XListProperties, it still returns an Atom list.
Signed-off-by: Peter Hutterer <peter.hutterer@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/XIProperties.c | 48 |
1 files changed, 17 insertions, 31 deletions
diff --git a/src/XIProperties.c b/src/XIProperties.c index 8b1bdcd..26ea574 100644 --- a/src/XIProperties.c +++ b/src/XIProperties.c @@ -68,7 +68,7 @@ XIListProperties(Display* dpy, int deviceid, int *num_props_return) goto cleanup; } - _XRead32(dpy, props, rep.num_properties << 2); + _XRead32(dpy, (long*)props, rep.num_properties << 2); } *num_props_return = rep.num_properties; @@ -197,35 +197,7 @@ XIGetProperty(Display* dpy, int deviceid, Atom property, long offset, *data = NULL; if (rep.type != None) { - /* - * One extra byte is malloced than is needed to contain the property - * data, but this last byte is null terminated and convenient for - * returning string properties, so the client doesn't then have to - * recopy the string to make it null terminated. - */ - switch (rep.format) { - case 8: - nbytes = rep.num_items; - rbytes = rep.num_items + 1; - if (rbytes > 0 && (*data = Xmalloc(rbytes))) - _XReadPad (dpy, (char *) *data, nbytes); - break; - - case 16: - nbytes = rep.num_items << 1; - rbytes = rep.num_items * sizeof(uint16_t) + 1; - if (rbytes > 0 && (*data = Xmalloc(rbytes))) - _XRead16Pad (dpy, (uint16_t*) *data, nbytes); - break; - - case 32: - nbytes = rep.num_items << 2; - rbytes = rep.num_items * sizeof(uint32_t) + 1; - if (rbytes > 0 && (*data = Xmalloc(rbytes))) - _XRead32 (dpy, (uint32_t*) *data, nbytes); - break; - - default: + if (rep.format != 8 && rep.format != 16 && rep.format != 32) { /* * This part of the code should never be reached. If it is, * the server sent back a property with an invalid format. @@ -235,13 +207,27 @@ XIGetProperty(Display* dpy, int deviceid, Atom property, long offset, UnlockDisplay(dpy); SyncHandle(); return(BadImplementation); - } + } + + /* + * One extra byte is malloced than is needed to contain the property + * data, but this last byte is null terminated and convenient for + * returning string properties, so the client doesn't then have to + * recopy the string to make it null terminated. + */ + + nbytes = rep.num_items * rep.format/8; + rbytes = nbytes + 1; + *data = Xmalloc(rbytes); + if (!(*data)) { _XEatData(dpy, nbytes); UnlockDisplay(dpy); SyncHandle(); return(BadAlloc); } + + _XReadPad (dpy, (char *)*data, nbytes); (*data)[rbytes - 1] = '\0'; } |