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 <ran234@gmail.com>
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);
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;
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);
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))
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);
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)
{
{
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]);
}
}