From 813ddf255d076efe65c953ff5dc6521839ab052b Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sat, 24 Mar 2012 00:29:33 +0200 Subject: [PATCH] Silence -Wcast-qual warnings There are some cases where we must free a string with a const qualifier. Add a macro UNCONSTIFY to trick the compiler into silencing the warning in the cases where we know what we're doing. Signed-off-by: Ran Benita --- src/alloc.c | 8 ++++---- src/malloc.c | 6 +++--- src/utils.h | 7 +++++++ src/xkbcomp/indicators.c | 2 +- src/xkbcomp/keycodes.c | 2 +- src/xkbcomp/symbols.c | 2 +- 6 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 1a46fbb..3b4e33a 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -181,18 +181,18 @@ XkbcFreeNames(struct xkb_desc * xkb) for (i = 0; i < map->num_types; i++, type++) { int j; for (j = 0; j < type->num_levels; j++) - free((char *) type->level_names[i]); + free(UNCONSTIFY(type->level_names[i])); free(type->level_names); type->level_names = NULL; } } for (i = 0; i < XkbNumVirtualMods; i++) - free((char *) names->vmods[i]); + free(UNCONSTIFY(names->vmods[i])); for (i = 0; i < XkbNumIndicators; i++) - free((char *) names->indicators[i]); + free(UNCONSTIFY(names->indicators[i])); for (i = 0; i < XkbNumKbdGroups; i++) - free((char *) names->groups[i]); + free(UNCONSTIFY(names->groups[i])); free(names->keys); free(names->key_aliases); diff --git a/src/malloc.c b/src/malloc.c index cff30d7..3818cdd 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -225,7 +225,7 @@ XkbcCopyKeyType(struct xkb_key_type * from, struct xkb_key_type * into) free(into->preserve); into->preserve= NULL; for (i = 0; i < into->num_levels; i++) - free((char *) into->level_names[i]); + free(UNCONSTIFY(into->level_names[i])); free(into->level_names); into->level_names = NULL; @@ -401,9 +401,9 @@ XkbcFreeClientMap(struct xkb_desc * xkb) free(type->map); free(type->preserve); for (j = 0; j < type->num_levels; j++) - free((char *) type->level_names[j]); + free(UNCONSTIFY(type->level_names[j])); free(type->level_names); - free((char *) type->name); + free(UNCONSTIFY(type->name)); } free(map->types); free(map->key_sym_map); diff --git a/src/utils.h b/src/utils.h index cbf3552..630fa48 100644 --- a/src/utils.h +++ b/src/utils.h @@ -40,6 +40,13 @@ extern void * recalloc(void *ptr, size_t old_size, size_t new_size); +/* + * We sometimes malloc strings and then expose them as const char*'s. This + * macro is used when we free these strings in order to avoid -Wcast-qual + * errors. + */ +#define UNCONSTIFY(const_ptr) ((void *)(uintptr_t)(const_ptr)) + #define uTypedAlloc(t) malloc(sizeof(t)) #define uTypedCalloc(n, t) calloc((n), sizeof(t)) #define uTypedRealloc(pO, n, t) realloc((pO), (n) * sizeof(t)) diff --git a/src/xkbcomp/indicators.c b/src/xkbcomp/indicators.c index ed40be1..5f00916 100644 --- a/src/xkbcomp/indicators.c +++ b/src/xkbcomp/indicators.c @@ -423,7 +423,7 @@ CopyIndicatorMapDefs(struct xkb_desc * xkb, LEDInfo *leds, LEDInfo **unboundRtrn im->ctrls = led->ctrls; if (xkb->names != NULL) { - free((char *) xkb->names->indicators[led->indicator - 1]); + free(UNCONSTIFY(xkb->names->indicators[led->indicator - 1])); xkb->names->indicators[led->indicator-1] = XkbcAtomGetString(led->name); } free(led); diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c index 50d8484..6a05dc2 100644 --- a/src/xkbcomp/keycodes.c +++ b/src/xkbcomp/keycodes.c @@ -914,7 +914,7 @@ CompileKeycodes(XkbFile *file, struct xkb_desc * xkb, unsigned merge) for (ii = info.leds; ii != NULL; ii = (IndicatorNameInfo *) ii->defs.next) { - free((char *) xkb->names->indicators[ii->ndx - 1]); + free(UNCONSTIFY(xkb->names->indicators[ii->ndx - 1])); xkb->names->indicators[ii->ndx - 1] = XkbcAtomGetString(ii->name); if (xkb->indicators != NULL) { diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index 8e00038..188d649 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -2017,7 +2017,7 @@ CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge) { if (info.groupNames[i] != None) { - free((char *) xkb->names->groups[i]); + free(UNCONSTIFY(xkb->names->groups[i])); xkb->names->groups[i] = XkbcAtomGetString(info.groupNames[i]); } } -- 2.7.4