[PATCH:libxkbfile] Add const attributes to fix gcc -Wwrite-strings warnings

Alan Coopersmith alan.coopersmith at oracle.com
Fri Nov 11 21:58:36 PST 2011


Does not fix all of them, as some affect the API and thus need more analysis.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 include/X11/extensions/XKBfile.h |    4 ++--
 src/maprules.c                   |    2 +-
 src/xkbbells.c                   |    2 +-
 src/xkbconfig.c                  |    2 +-
 src/xkberrs.c                    |    4 ++--
 src/xkbmisc.c                    |    2 +-
 src/xkbout.c                     |    6 +++---
 src/xkbtext.c                    |   20 +++++++++++---------
 8 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/include/X11/extensions/XKBfile.h b/include/X11/extensions/XKBfile.h
index 6d5e910..0d2f52b 100644
--- a/include/X11/extensions/XKBfile.h
+++ b/include/X11/extensions/XKBfile.h
@@ -83,9 +83,9 @@ typedef void	(*XkbFileAddOnFunc)(
 #define	_XkbErrXReqFailure		25
 #define	_XkbErrBadImplementation	26
 
-extern char *		_XkbErrMessages[];
+extern const char *	_XkbErrMessages[];
 extern unsigned		_XkbErrCode;
-extern char *		_XkbErrLocation;
+extern const char *	_XkbErrLocation;
 extern unsigned		_XkbErrData;
 
 /***====================================================================***/
diff --git a/src/maprules.c b/src/maprules.c
index 3507852..81102a3 100644
--- a/src/maprules.c
+++ b/src/maprules.c
@@ -238,7 +238,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"
 };
diff --git a/src/xkbbells.c b/src/xkbbells.c
index 1571d1e..10b2725 100644
--- a/src/xkbbells.c
+++ b/src/xkbbells.c
@@ -31,7 +31,7 @@
 #include <X11/XKBlib.h>
 #include "XKBbells.h"
 
-static char *_xkbStdBellNames[XkbBI_NumBells] = {
+static const char *_xkbStdBellNames[XkbBI_NumBells] = {
 	"Info",
 	"Warning",
 	"MinorError",
diff --git a/src/xkbconfig.c b/src/xkbconfig.c
index 1934983..b60017f 100644
--- a/src/xkbconfig.c
+++ b/src/xkbconfig.c
@@ -1307,7 +1307,7 @@ BAILOUT:
 void
 XkbCFReportError(FILE *file,char *name,int error,int line)
 {
-char *	msg;
+const char *msg;
 
     switch(error) {
 	case XkbCF_BadAlloc:
diff --git a/src/xkberrs.c b/src/xkberrs.c
index a34417a..f28f02b 100644
--- a/src/xkberrs.c
+++ b/src/xkberrs.c
@@ -41,7 +41,7 @@
 #include <X11/XKBlib.h>
 #include <X11/extensions/XKBfile.h>
 
-char *		_XkbErrMessages[] = {
+const char *	_XkbErrMessages[] = {
 	"success",				/* _XkbSuccess		     */
 	"key names not defined",		/* _XkbErrMissingNames	     */
 	"key types not defined",		/* _XkbErrMissingTypes	     */
@@ -72,6 +72,6 @@ char *		_XkbErrMessages[] = {
 };
 
 unsigned	_XkbErrCode;
-char *		_XkbErrLocation= NULL;
+const char *	_XkbErrLocation= NULL;
 unsigned	_XkbErrData;
 
diff --git a/src/xkbmisc.c b/src/xkbmisc.c
index 314580e..e0b9bd6 100644
--- a/src/xkbmisc.c
+++ b/src/xkbmisc.c
@@ -218,7 +218,7 @@ int		nG,eG;
 /***===================================================================***/
 
 static Bool
-XkbWriteSectionFromName(FILE *file,char *sectionName,char *name)
+XkbWriteSectionFromName(FILE *file, const char *sectionName, const char *name)
 {
     fprintf(file,"    xkb_%-20s { include \"%s\" };\n",sectionName,name);
     return True;
diff --git a/src/xkbout.c b/src/xkbout.c
index ad1fd03..91cd1ba 100644
--- a/src/xkbout.c
+++ b/src/xkbout.c
@@ -129,7 +129,7 @@ Atom			kcName;
 register unsigned 	i;
 XkbDescPtr		xkb;
 Display *		dpy;
-char *			alternate;
+const char *		alternate;
 
     xkb= result->xkb;
     if ((!xkb)||(!xkb->names)||(!xkb->names->keys)) {
@@ -156,7 +156,7 @@ char *			alternate;
     }
     if (xkb->indicators!=NULL) {
 	for (i=0;i<XkbNumIndicators;i++) {
-	    char *type;
+	    const char *type;
 	    if (xkb->indicators->phys_indicators&(1<<i))
 			type= "    ";
 	    else	type= "    virtual ";
@@ -433,7 +433,7 @@ Bool			showActions;
 	   						(showImplicit)) {
 		int 	typeNdx,g;
 		Bool	multi;
-		char *	comment="  ";
+		const char *	comment="  ";
 
 		if ((srv->explicit[i]&XkbExplicitKeyTypesMask)==0)
 		    comment= "//";
diff --git a/src/xkbtext.c b/src/xkbtext.c
index 3eabb5d..3a82b17 100644
--- a/src/xkbtext.c
+++ b/src/xkbtext.c
@@ -229,7 +229,7 @@ char *str,buf[BUFFER_SIZE];
     return rtrn;
 }
 
-static char *modNames[XkbNumModifiers] = {
+static const char *modNames[XkbNumModifiers] = {
     "Shift", "Lock", "Control", "Mod1", "Mod2", "Mod3", "Mod4", "Mod5"
 };
 
@@ -423,7 +423,7 @@ char *rtrn;
 
 /***====================================================================***/
 
-static char *imWhichNames[]= {
+static const char *imWhichNames[]= {
 	"base",
 	"latched",
 	"locked",
@@ -477,7 +477,8 @@ char *		buf;
 char *
 XkbAccessXDetailText(unsigned state,unsigned format)
 {
-char *buf,*prefix;
+char *buf;
+const char *prefix;
 
     buf= tbGetBuffer(32);
     if (format==XkbMessage)	prefix= "";
@@ -495,7 +496,7 @@ char *buf,*prefix;
     return buf;
 }
 
-static char *nknNames[] = {
+static const char *nknNames[] = {
 	"keycodes", "geometry", "deviceID"
 };
 #define	NUM_NKN	(sizeof(nknNames)/sizeof(char *))
@@ -503,14 +504,15 @@ static char *nknNames[] = {
 char *
 XkbNKNDetailMaskText(unsigned detail,unsigned format)
 {
-char *buf,*prefix,*suffix;
+char *buf;
+const char *prefix,*suffix;
 register int 		i;
 register unsigned	bit;
 int			len,plen,slen;
 
 
     if ((detail&XkbAllNewKeyboardEventsMask)==0) {
-	char *tmp = "";
+	const char *tmp = "";
 	if (format==XkbCFile)			tmp= "0";
 	else if (format==XkbMessage)		tmp= "none";
 	buf=  tbGetBuffer(strlen(tmp)+1);
@@ -518,7 +520,7 @@ int			len,plen,slen;
 	return buf;
     }
     else if ((detail&XkbAllNewKeyboardEventsMask)==XkbAllNewKeyboardEventsMask){
-	char *	tmp;
+	const char *	tmp;
 	if (format==XkbCFile)		tmp= "XkbAllNewKeyboardEventsMask";
 	else 				tmp= "all";
 	buf=  tbGetBuffer(strlen(tmp)+1);
@@ -568,7 +570,7 @@ int			len,plen,slen;
     return buf;
 }
 
-static char *ctrlNames[] = {
+static const char *ctrlNames[] = {
 	"repeatKeys",
 	"slowKeys",
 	"bounceKeys",
@@ -772,7 +774,7 @@ char *rtrn;
 /***====================================================================***/
 
 static int
-TryCopyStr(char *to,char *from,int *pLeft)
+TryCopyStr(char *to,const char *from,int *pLeft)
 {
 register int len;
     if (*pLeft>0) {
-- 
1.7.3.2



More information about the xorg-devel mailing list