[PATCH libxkbcommon 08/11] Fix all constness warnings

Ran Benita ran234 at gmail.com
Sat Feb 25 02:13:33 PST 2012


These are all trivial/obvious fixes which clear a bunch of warnings.

Signed-off-by: Ran Benita <ran234 at gmail.com>
---
 src/keysym.c             |    2 +-
 src/maprules.c           |   44 ++++++++++++++++++++++++--------------------
 src/text.c               |   29 +++++++++++++++--------------
 src/xkbcomp/action.c     |    3 ++-
 src/xkbcomp/alias.c      |    8 ++++----
 src/xkbcomp/expr.c       |    6 +++---
 src/xkbcomp/geometry.c   |    6 +++---
 src/xkbcomp/keycodes.c   |    2 +-
 src/xkbcomp/keycodes.h   |    2 +-
 src/xkbcomp/keytypes.c   |    2 +-
 src/xkbcomp/listing.c    |    2 +-
 src/xkbcomp/parseutils.h |    2 +-
 src/xkbcomp/xkbcomp.c    |   12 ++++++------
 src/xkbcomp/xkbpath.c    |    2 +-
 src/xkbcomp/xkbpath.h    |    2 +-
 src/xkbcomp/xkbscan.l    |    2 +-
 src/xkbmisc.h            |   18 +++++++++---------
 src/xkbrules.h           |    8 ++++----
 18 files changed, 79 insertions(+), 73 deletions(-)

diff --git a/src/keysym.c b/src/keysym.c
index 5ff1313..7580cdd 100644
--- a/src/keysym.c
+++ b/src/keysym.c
@@ -114,7 +114,7 @@ xkb_string_to_keysym(const char *s)
         entry = &_XkeyTable[idx];
 
         if ((entry[0] == sig1) && (entry[1] == sig2) &&
-            !strcmp(s, (char *)entry + 6))
+            !strcmp(s, (const char *)entry + 6))
         {
             val = (entry[2] << 24) | (entry[3] << 16) |
                   (entry[4] << 8)  | entry[5];
diff --git a/src/maprules.c b/src/maprules.c
index 894f202..49761be 100644
--- a/src/maprules.c
+++ b/src/maprules.c
@@ -208,7 +208,7 @@ Bool	endOfFile,spacePending,slashPending,inComment;
 #define	PART_MASK	0x000F
 #define	COMPONENT_MASK	0x03F0
 
-static	char *	cname[MAX_WORDS] = {
+static	const char * cname[MAX_WORDS] = {
 	"model", "layout", "variant", "option",
 	"keycodes", "symbols", "types", "compat", "geometry", "keymap"
 };
@@ -228,9 +228,9 @@ typedef struct _FileSpec {
 } FileSpec;
 
 typedef struct {
-	char *			model;
-	char *			layout[XkbNumKbdGroups+1];
-	char *			variant[XkbNumKbdGroups+1];
+	const char *		model;
+	const char *		layout[XkbNumKbdGroups+1];
+	const char *		variant[XkbNumKbdGroups+1];
 	char *			options;
 } XkbRF_MultiDefsRec, *XkbRF_MultiDefsPtr;
 
@@ -531,11 +531,11 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
        } else {
            char *p;
            int i;
-           mdefs->layout[1] = _XkbDupString(defs->layout);
-	   if (mdefs->layout[1] == NULL)
-	      return False;
-           squeeze_spaces(mdefs->layout[1]);
-           p = mdefs->layout[1];
+           p = _XkbDupString(defs->layout);
+           if (p == NULL)
+              return False;
+           squeeze_spaces(p);
+           mdefs->layout[1] = p;
            for (i = 2; i <= XkbNumKbdGroups; i++) {
               if ((p = strchr(p, ','))) {
                  *p++ = '\0';
@@ -555,11 +555,11 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
        } else {
            char *p;
            int i;
-           mdefs->variant[1] = _XkbDupString(defs->variant);
-	   if (mdefs->variant[1] == NULL)
-	      return False;
-           squeeze_spaces(mdefs->variant[1]);
-           p = mdefs->variant[1];
+           p = _XkbDupString(defs->variant);
+           if (p == NULL)
+              return False;
+           squeeze_spaces(p);
+           mdefs->variant[1] = p;
            for (i = 2; i <= XkbNumKbdGroups; i++) {
               if ((p = strchr(p, ','))) {
                  *p++ = '\0';
@@ -578,9 +578,13 @@ MakeMultiDefs(XkbRF_MultiDefsPtr mdefs, XkbRF_VarDefsPtr defs)
 static void
 FreeMultiDefs(XkbRF_MultiDefsPtr defs)
 {
-  if (defs->options) free(defs->options);
-  if (defs->layout[1])  free(defs->layout[1]);
-  if (defs->variant[1])  free(defs->variant[1]);
+  if (defs->options)
+    free(defs->options);
+  /* Avoid -Wcast-qual warnings. */
+  if (defs->layout[1])
+    free((void *)(uintptr_t)defs->layout[1]);
+  if (defs->variant[1])
+     free((void *)(uintptr_t)defs->variant[1]);
 }
 
 static void
@@ -612,11 +616,11 @@ XkbRF_ApplyRule(	XkbRF_RulePtr 		rule,
 
 static Bool
 CheckGroup(	XkbRF_RulesPtr          rules,
-		char * 			group_name,
-		char * 			name)
+		const char * 		group_name,
+		const char * 		name)
 {
    int i;
-   char *p;
+   const char *p;
    XkbRF_GroupPtr group;
 
    for (i = 0, group = rules->groups; i < rules->num_groups; i++, group++) {
diff --git a/src/text.c b/src/text.c
index c913ff3..d5a7549 100644
--- a/src/text.c
+++ b/src/text.c
@@ -55,7 +55,7 @@ tbGetBuffer(unsigned int size)
     return rtrn;
 }
 
-static char *
+static const char *
 XkbcVModIndexText(struct xkb_desc * xkb, unsigned ndx)
 {
     int len;
@@ -89,11 +89,12 @@ XkbcVModIndexText(struct xkb_desc * xkb, unsigned ndx)
     return rtrn;
 }
 
-char *
+const char *
 XkbcVModMaskText(struct xkb_desc * xkb, unsigned modMask, unsigned mask)
 {
     int i, bit, len, rem;
-    char *mm = NULL, *rtrn, *str;
+    const char *mm = NULL;
+    char *rtrn, *str;
     char buf[BUFFER_SIZE];
 
     if ((modMask == 0) && (mask == 0))
@@ -138,7 +139,7 @@ XkbcVModMaskText(struct xkb_desc * xkb, unsigned modMask, unsigned mask)
     return rtrn;
 }
 
-static char *modNames[XkbNumModifiers] = {
+static const char *modNames[XkbNumModifiers] = {
     "Shift",
     "Lock",
     "Control",
@@ -149,7 +150,7 @@ static char *modNames[XkbNumModifiers] = {
     "Mod5"
 };
 
-char *
+const char *
 XkbcModIndexText(unsigned ndx)
 {
     char *buf;
@@ -165,7 +166,7 @@ XkbcModIndexText(unsigned ndx)
     return buf;
 }
 
-char *
+const char *
 XkbcModMaskText(unsigned mask, Bool cFormat)
 {
     int i, rem, bit;
@@ -198,7 +199,7 @@ XkbcModMaskText(unsigned mask, Bool cFormat)
     return buf;
 }
 
-char *
+const char *
 XkbcConfigText(unsigned config)
 {
     switch (config) {
@@ -228,7 +229,7 @@ XkbcConfigText(unsigned config)
     }
 }
 
-char *
+const char *
 XkbcGeomFPText(int val)
 {
     char *buf;
@@ -246,7 +247,7 @@ XkbcGeomFPText(int val)
     return buf;
 }
 
-static char *actionTypeNames[XkbSA_NumActions]= {
+static const char *actionTypeNames[XkbSA_NumActions]= {
     "NoAction",         /* XkbSA_NoAction */
     "SetMods",          /* XkbSA_SetMods */
     "LatchMods",        /* XkbSA_LatchMods */
@@ -270,7 +271,7 @@ static char *actionTypeNames[XkbSA_NumActions]= {
     "DeviceValuator"    /* XkbSA_DeviceValuator */
 };
 
-char *
+const char *
 XkbcActionTypeText(unsigned type)
 {
     if (type <= XkbSA_LastAction)
@@ -278,7 +279,7 @@ XkbcActionTypeText(unsigned type)
     return "Private";
 }
 
-char *
+const char *
 XkbcKeysymText(uint32_t sym)
 {
     static char buffer[16];
@@ -288,7 +289,7 @@ XkbcKeysymText(uint32_t sym)
     return buffer;
 }
 
-char *
+const char *
 XkbcKeyNameText(char *name)
 {
     char *buf;
@@ -305,7 +306,7 @@ XkbcKeyNameText(char *name)
     return buf;
 }
 
-static char *siMatchText[5] = {
+static const char *siMatchText[5] = {
     "NoneOf",       /* XkbSI_NoneOf */
     "AnyOfOrNone",  /* XkbSI_AnyOfOrNone */
     "AnyOf",        /* XkbSI_AnyOf */
@@ -313,7 +314,7 @@ static char *siMatchText[5] = {
     "Exactly"       /* XkbSI_Exactly */
 };
 
-char *
+const char *
 XkbcSIMatchText(unsigned type)
 {
     char *buf;
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index f87b5ef..e065919 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -323,7 +323,8 @@ ReportActionNotArray(unsigned action, unsigned field)
 }
 
 static Bool
-ReportNotFound(unsigned action, unsigned field, const char *what, char *bad)
+ReportNotFound(unsigned action, unsigned field, const char *what,
+               const char *bad)
 {
     ERROR("%s named %s not found\n", what, bad);
     ACTION("Ignoring the %s field of an %s action\n", fieldText(field),
diff --git a/src/xkbcomp/alias.c b/src/xkbcomp/alias.c
index 32d2e1e..35c5273 100644
--- a/src/xkbcomp/alias.c
+++ b/src/xkbcomp/alias.c
@@ -213,10 +213,10 @@ ApplyAliases(struct xkb_desc * xkb, Bool toGeom, AliasInfo ** info_in)
             {
                 if (strncmp(a->alias, info->alias, XkbKeyNameLength) == 0)
                 {
-                    AliasInfo old;
-                    InitAliasInfo(&old, MergeAugment, 0, a->alias, a->real);
-                    HandleCollision(&old, info);
-                    memcpy(old.real, a->real, XkbKeyNameLength);
+                    AliasInfo old_info;
+                    InitAliasInfo(&old_info, MergeAugment, 0, a->alias, a->real);
+                    HandleCollision(&old_info, info);
+                    memcpy(old_info.real, a->real, XkbKeyNameLength);
                     info->alias[0] = '\0';
                     nNew--;
                     break;
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index 13f8745..c5b8655 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -713,7 +713,7 @@ ExprResolveString(ExprDef * expr,
     ExprResult leftRtrn, rightRtrn;
     ExprDef *left;
     ExprDef *right;
-    char *bogus = NULL;
+    const char *bogus = NULL;
 
     switch (expr->op)
     {
@@ -795,7 +795,7 @@ int
 ExprResolveKeyName(ExprDef * expr,
                    ExprResult * val_rtrn)
 {
-    char *bogus = NULL;
+    const char *bogus = NULL;
 
     switch (expr->op)
     {
@@ -893,7 +893,7 @@ ExprResolveMaskLookup(ExprDef * expr,
     int ok = 0;
     ExprResult leftRtrn, rightRtrn;
     ExprDef *left, *right;
-    char *bogus = NULL;
+    const char *bogus = NULL;
 
     switch (expr->op)
     {
diff --git a/src/xkbcomp/geometry.c b/src/xkbcomp/geometry.c
index c6e7ba1..fb5eef2 100644
--- a/src/xkbcomp/geometry.c
+++ b/src/xkbcomp/geometry.c
@@ -1505,7 +1505,7 @@ SetTextDoodadField(DoodadInfo * di,
     ExprResult tmp;
     unsigned def;
     unsigned type;
-    char *typeName = "text doodad";
+    const char *typeName = "text doodad";
     union
     {
         uint32_t *str;
@@ -1695,7 +1695,7 @@ SetLogoDoodadField(DoodadInfo * di,
                    ExprDef * value, SectionInfo * si, GeometryInfo * info)
 {
     ExprResult tmp;
-    char *typeName = "logo doodad";
+    const char *typeName = "logo doodad";
 
     if ((!uStrCaseCmp(field, "corner"))
         || (!uStrCaseCmp(field, "cornerradius")))
@@ -2859,7 +2859,7 @@ HandleGeometryFile(XkbFile * file,
                    struct xkb_desc * xkb, unsigned merge, GeometryInfo * info)
 {
     ParseCommon *stmt;
-    char *failWhat;
+    const char *failWhat;
 
     if (merge == MergeDefault)
         merge = MergeAugment;
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index e8d19db..e24764e 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -32,7 +32,7 @@
 #include "misc.h"
 #include "alias.h"
 
-char *
+const char *
 longText(unsigned long val)
 {
     char buf[4];
diff --git a/src/xkbcomp/keycodes.h b/src/xkbcomp/keycodes.h
index 37702ac..c64b082 100644
--- a/src/xkbcomp/keycodes.h
+++ b/src/xkbcomp/keycodes.h
@@ -29,7 +29,7 @@
 
 #define	KeyNameToLong(n)	((((unsigned long)n[0])<<24)|(((unsigned long)n[1])<<16)|(((unsigned long)n[2])<<8)|n[3])
 
-extern char *longText(unsigned long /* val */
+extern const char *longText(unsigned long /* val */
     );
 
 extern void LongToKeyName(unsigned long /* val */ ,
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index f00a521..12ea942 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -547,7 +547,7 @@ AddPreserve(struct xkb_desc * xkb,
         }
         if (report && (warningLevel > 0))
         {
-            char *str;
+            const char *str;
             WARN("Multiple definitions for preserve[%s] in %s\n",
                   PreserveIndexTxt(xkb, old), TypeTxt(type));
 
diff --git a/src/xkbcomp/listing.c b/src/xkbcomp/listing.c
index dbedca6..0fe8288 100644
--- a/src/xkbcomp/listing.c
+++ b/src/xkbcomp/listing.c
@@ -363,7 +363,7 @@ AddDirectory(CompPair *cp, char *head, char *ptrn, char *rest, char *map,
 
 static int
 GenerateComponent(struct xkb_component_list * complist, unsigned type, char *head_in,
-                 char *base, int *max)
+                 const char *base, int *max)
 {
     char *str, *head, *ptrn = NULL, *rest = NULL;
     char buf[PATH_MAX];
diff --git a/src/xkbcomp/parseutils.h b/src/xkbcomp/parseutils.h
index dea25e6..c646494 100644
--- a/src/xkbcomp/parseutils.h
+++ b/src/xkbcomp/parseutils.h
@@ -183,7 +183,7 @@ extern void yyerror(const char *        /* s */
 extern int yylex(void);
 extern int yyparse(void);
 
-extern void setScanState(char * /* file */ ,
+extern void setScanState(const char * /* file */ ,
                          int     /* line */
     );
 
diff --git a/src/xkbcomp/xkbcomp.c b/src/xkbcomp/xkbcomp.c
index cc3b52d..45a385b 100644
--- a/src/xkbcomp/xkbcomp.c
+++ b/src/xkbcomp/xkbcomp.c
@@ -68,7 +68,7 @@ XkbKeymapFileFromComponents(const struct xkb_component_names * ktcsg)
     geometry = CreateXKBFile(XkmGeometryIndex, NULL, (ParseCommon *)inc, 0);
     AppendStmt(&keycodes->common, &geometry->common);
 
-    return CreateXKBFile(XkmKeymapFile, ktcsg->keymap ? ktcsg->keymap : "",
+    return CreateXKBFile(XkmKeymapFile, ktcsg->keymap ? ktcsg->keymap : strdup(""),
                          &keycodes->common, 0);
 }
 
@@ -90,7 +90,7 @@ XkbComponentsFromRules(const char *rules, const XkbRF_VarDefsPtr defs)
     }
 
     if (!loaded) {
-        rulesFile = XkbFindFileInPath((char *)rules, XkmRulesFile, &rulesPath);
+        rulesFile = XkbFindFileInPath(rules, XkmRulesFile, &rulesPath);
         if (!rulesFile) {
             ERROR("could not find \"%s\" rules in XKB path\n", rules);
             goto out;
@@ -146,10 +146,10 @@ xkb_compile_keymap_from_rules(const struct xkb_rule_names *rmlvo)
         return NULL;
     }
 
-    defs.model = (char *) rmlvo->model;
-    defs.layout = (char *) rmlvo->layout;
-    defs.variant = (char *) rmlvo->variant;
-    defs.options = (char *) rmlvo->options;
+    defs.model = rmlvo->model;
+    defs.layout = rmlvo->layout;
+    defs.variant = rmlvo->variant;
+    defs.options = rmlvo->options;
 
     names = XkbComponentsFromRules(rmlvo->rules, &defs);
     if (!names) {
diff --git a/src/xkbcomp/xkbpath.c b/src/xkbcomp/xkbpath.c
index c1a0f01..be256b5 100644
--- a/src/xkbcomp/xkbpath.c
+++ b/src/xkbcomp/xkbpath.c
@@ -399,7 +399,7 @@ XkbFindFileInCache(char *name, unsigned type, char **pathRtrn)
  * pathRtrn is undefined.
  */
 FILE *
-XkbFindFileInPath(char *name, unsigned type, char **pathRtrn)
+XkbFindFileInPath(const char *name, unsigned type, char **pathRtrn)
 {
     register int i;
     FILE *file = NULL;
diff --git a/src/xkbcomp/xkbpath.h b/src/xkbcomp/xkbpath.h
index ca818a5..f527d19 100644
--- a/src/xkbcomp/xkbpath.h
+++ b/src/xkbcomp/xkbpath.h
@@ -34,7 +34,7 @@
 extern char *XkbDirectoryForInclude(unsigned    /* type */
     );
 
-extern FILE *XkbFindFileInPath(char * /* name */ ,
+extern FILE *XkbFindFileInPath(const char * /* name */ ,
                                unsigned /* type */ ,
                                char **  /* pathRtrn */
     );
diff --git a/src/xkbcomp/xkbscan.l b/src/xkbcomp/xkbscan.l
index d32cf39..83f0db0 100644
--- a/src/xkbcomp/xkbscan.l
+++ b/src/xkbcomp/xkbscan.l
@@ -194,7 +194,7 @@ yyerror(const char *s)
     return;
 }
 
-void setScanState(char *file, int lineno)
+void setScanState(const char *file, int lineno)
 {
   yylineno = 1;
   if (scanFile)
diff --git a/src/xkbmisc.h b/src/xkbmisc.h
index 6600d52..40f1334 100644
--- a/src/xkbmisc.h
+++ b/src/xkbmisc.h
@@ -75,31 +75,31 @@ XkbcAtomGetString(uint32_t atom);
 extern const char *
 XkbcAtomText(uint32_t atm);
 
-extern char *
+extern const char *
 XkbcVModMaskText(struct xkb_desc * xkb, unsigned modMask, unsigned mask);
 
-extern char *
+extern const char *
 XkbcModIndexText(unsigned ndx);
 
-extern char *
+extern const char *
 XkbcModMaskText(unsigned mask, Bool cFormat);
 
-extern char *
+extern const char *
 XkbcConfigText(unsigned config);
 
-extern char *
+extern const char *
 XkbcGeomFPText(int val);
 
-extern char *
+extern const char *
 XkbcActionTypeText(unsigned type);
 
-extern char *
+extern const char *
 XkbcKeysymText(uint32_t sym);
 
-extern char *
+extern const char *
 XkbcKeyNameText(char *name);
 
-extern char *
+extern const char *
 XkbcSIMatchText(unsigned type);
 
 #endif /* _XKBMISC_H_ */
diff --git a/src/xkbrules.h b/src/xkbrules.h
index c9082f5..08c1c04 100644
--- a/src/xkbrules.h
+++ b/src/xkbrules.h
@@ -74,10 +74,10 @@ authorization from the authors.
 #define _XkbErrBadImplementation    26
 
 typedef struct _XkbRF_VarDefs {
-    char *          model;
-    char *          layout;
-    char *          variant;
-    char *          options;
+    const char *    model;
+    const char *    layout;
+    const char *    variant;
+    const char *    options;
     unsigned short  sz_extra;
     unsigned short  num_extra;
     char *          extra_names;
-- 
1.7.9.2



More information about the xorg-devel mailing list