summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@sun.com>2009-02-02 19:25:14 -0800
committerAlan Coopersmith <alan.coopersmith@sun.com>2009-02-03 10:06:00 -0800
commit5623c27700b7b23a8dbbd8c8f45e5d4fa0c667e3 (patch)
tree5ef32d8457f859742bcf2aa12019306db49d5c25
parent6869efae74381e5305b2d6517bf286e3ef7fdcb7 (diff)
Constify atom name strings
Changes MakeAtom to take a const char * and NameForAtom to return them, since many callers pass pointers to constant strings stored in read-only ELF sections. Updates in-tree callers as necessary to clear const mismatch warnings introduced by this change. Signed-off-by: Alan Coopersmith <alan.coopersmith@sun.com> Acked-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--dix/atom.c15
-rw-r--r--dix/dispatch.c2
-rw-r--r--hw/dmx/dmxfont.c4
-rw-r--r--hw/kdrive/ephyr/ephyrvideo.c2
-rw-r--r--hw/xnest/Font.c4
-rw-r--r--include/dix.h4
-rw-r--r--include/xkbsrv.h2
-rw-r--r--xfixes/cursor.c4
-rw-r--r--xkb/xkb.c2
-rw-r--r--xkb/xkbfmisc.c2
-rw-r--r--xkb/xkbtext.c18
-rw-r--r--xkb/xkmread.c2
12 files changed, 33 insertions, 28 deletions
diff --git a/dix/atom.c b/dix/atom.c
index ab9ee800a..f5bf8ad7e 100644
--- a/dix/atom.c
+++ b/dix/atom.c
@@ -64,7 +64,7 @@ typedef struct _Node {
struct _Node *left, *right;
Atom a;
unsigned int fingerPrint;
- char *string;
+ const char *string;
} NodeRec, *NodePtr;
static Atom lastAtom = None;
@@ -75,7 +75,7 @@ static NodePtr *nodeTable;
void FreeAtom(NodePtr patom);
Atom
-MakeAtom(char *string, unsigned len, Bool makeit)
+MakeAtom(const char *string, unsigned len, Bool makeit)
{
NodePtr * np;
unsigned i;
@@ -118,13 +118,14 @@ MakeAtom(char *string, unsigned len, Bool makeit)
}
else
{
- nd->string = xalloc(len + 1);
- if (!nd->string) {
+ char *newstring = xalloc(len + 1);
+ if (!newstring) {
xfree(nd);
return BAD_RESOURCE;
}
- strncpy(nd->string, string, (int)len);
- nd->string[len] = 0;
+ strncpy(newstring, string, (int)len);
+ newstring[len] = 0;
+ nd->string = newstring;
}
if ((lastAtom + 1) >= tableLength) {
NodePtr *table;
@@ -157,7 +158,7 @@ ValidAtom(Atom atom)
return (atom != None) && (atom <= lastAtom);
}
-char *
+const char *
NameForAtom(Atom atom)
{
NodePtr node;
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 5cde80b2d..b06f4aa85 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -901,7 +901,7 @@ ProcInternAtom(ClientPtr client)
int
ProcGetAtomName(ClientPtr client)
{
- char *str;
+ const char *str;
xGetAtomNameReply reply;
int len;
REQUEST(xResourceReq);
diff --git a/hw/dmx/dmxfont.c b/hw/dmx/dmxfont.c
index b70f7d2df..c33aee79a 100644
--- a/hw/dmx/dmxfont.c
+++ b/hw/dmx/dmxfont.c
@@ -253,7 +253,7 @@ Bool dmxBELoadFont(ScreenPtr pScreen, FontPtr pFont)
{
DMXScreenInfo *dmxScreen = &dmxScreens[pScreen->myNum];
dmxFontPrivPtr pFontPriv = FontGetPrivate(pFont, dmxFontPrivateIndex);
- char *name;
+ const char *name;
char **oldFontPath = NULL;
int nOldPaths;
Atom name_atom, value_atom;
@@ -415,7 +415,7 @@ Bool dmxBELoadFont(ScreenPtr pScreen, FontPtr pFont)
}
if (!value_atom) return FALSE;
- name = (char *)NameForAtom(value_atom);
+ name = NameForAtom(value_atom);
if (!name) return FALSE;
pFontPriv->font[pScreen->myNum] =
diff --git a/hw/kdrive/ephyr/ephyrvideo.c b/hw/kdrive/ephyr/ephyrvideo.c
index c4eb06607..5058ebe03 100644
--- a/hw/kdrive/ephyr/ephyrvideo.c
+++ b/hw/kdrive/ephyr/ephyrvideo.c
@@ -236,7 +236,7 @@ DoSimpleClip (BoxPtr a_dst_box,
static Bool
ephyrLocalAtomToHost (int a_local_atom, int *a_host_atom)
{
- char *atom_name=NULL;
+ const char *atom_name=NULL;
int host_atom=None ;
EPHYR_RETURN_VAL_IF_FAIL (a_host_atom, FALSE) ;
diff --git a/hw/xnest/Font.c b/hw/xnest/Font.c
index 26faf1633..7b388f0f4 100644
--- a/hw/xnest/Font.c
+++ b/hw/xnest/Font.c
@@ -40,7 +40,7 @@ xnestRealizeFont(ScreenPtr pScreen, FontPtr pFont)
int nprops;
FontPropPtr props;
int i;
- char *name;
+ const char *name;
FontSetPrivate(pFont, xnestFontPrivateIndex, NULL);
@@ -58,7 +58,7 @@ xnestRealizeFont(ScreenPtr pScreen, FontPtr pFont)
if (!value_atom) return False;
- name = (char *)NameForAtom(value_atom);
+ name = NameForAtom(value_atom);
if (!name) return False;
diff --git a/include/dix.h b/include/dix.h
index b21084607..658dd293c 100644
--- a/include/dix.h
+++ b/include/dix.h
@@ -280,14 +280,14 @@ extern _X_EXPORT Bool ClientIsAsleep(
/* atom.c */
extern _X_EXPORT Atom MakeAtom(
- char * /*string*/,
+ const char * /*string*/,
unsigned /*len*/,
Bool /*makeit*/);
extern _X_EXPORT Bool ValidAtom(
Atom /*atom*/);
-extern _X_EXPORT char *NameForAtom(
+extern _X_EXPORT const char *NameForAtom(
Atom /*atom*/);
extern _X_EXPORT void AtomError(void);
diff --git a/include/xkbsrv.h b/include/xkbsrv.h
index 8f6a767d9..449722058 100644
--- a/include/xkbsrv.h
+++ b/include/xkbsrv.h
@@ -880,7 +880,7 @@ extern _X_EXPORT XkbGeometryPtr XkbLookupNamedGeometry(
);
extern _X_EXPORT char * _XkbDupString(
- char * /* str */
+ const char * /* str */
);
extern _X_EXPORT void XkbConvertCase(
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
index 2c584f9f4..cd3df12bc 100644
--- a/xfixes/cursor.c
+++ b/xfixes/cursor.c
@@ -457,7 +457,7 @@ ProcXFixesGetCursorName (ClientPtr client)
CursorPtr pCursor;
xXFixesGetCursorNameReply reply;
REQUEST(xXFixesGetCursorNameReq);
- char *str;
+ const char *str;
int len;
REQUEST_SIZE_MATCH(xXFixesGetCursorNameReq);
@@ -507,7 +507,7 @@ ProcXFixesGetCursorImageAndName (ClientPtr client)
CursorPtr pCursor;
CARD32 *image;
int npixels;
- char *name;
+ const char *name;
int nbytes, nbytesRound;
int width, height;
int rc, x, y;
diff --git a/xkb/xkb.c b/xkb/xkb.c
index d889680c8..30d58bf17 100644
--- a/xkb/xkb.c
+++ b/xkb/xkb.c
@@ -3853,7 +3853,7 @@ register int i,bit;
static Bool
_XkbCheckTypeName(Atom name,int typeNdx)
{
-char * str;
+const char * str;
str= NameForAtom(name);
if ((strcmp(str,"ONE_LEVEL")==0)||(strcmp(str,"TWO_LEVEL")==0)||
diff --git a/xkb/xkbfmisc.c b/xkb/xkbfmisc.c
index be8accb35..aa660dfbe 100644
--- a/xkb/xkbfmisc.c
+++ b/xkb/xkbfmisc.c
@@ -163,7 +163,7 @@ XkbWriteXKBKeymapForNames( FILE * file,
unsigned want,
unsigned need)
{
-char * tmp;
+const char * tmp;
unsigned complete;
XkbNamesPtr old_names;
int multi_section;
diff --git a/xkb/xkbtext.c b/xkb/xkbtext.c
index b9f16a8cc..836d47e28 100644
--- a/xkb/xkbtext.c
+++ b/xkb/xkbtext.c
@@ -70,16 +70,17 @@ char *rtrn;
char *
XkbAtomText(Atom atm,unsigned format)
{
+const char *atmstr;
char *rtrn,*tmp;
- tmp= XkbAtomGetString(atm);
- if (tmp!=NULL) {
+ atmstr = XkbAtomGetString(atm);
+ if (atmstr != NULL) {
int len;
- len= strlen(tmp)+1;
+ len= strlen(atmstr)+1;
if (len>BUFFER_SIZE)
len= BUFFER_SIZE-2;
rtrn= tbGetBuffer(len);
- strncpy(rtrn,tmp,len);
+ strncpy(rtrn,atmstr,len);
rtrn[len]= '\0';
}
else {
@@ -104,7 +105,8 @@ XkbVModIndexText(XkbDescPtr xkb,unsigned ndx,unsigned format)
{
register int len;
register Atom *vmodNames;
-char *rtrn,*tmp;
+char *rtrn;
+const char *tmp;
char numBuf[20];
if (xkb && xkb->names)
@@ -116,8 +118,10 @@ char numBuf[20];
tmp= "illegal";
else if (vmodNames&&(vmodNames[ndx]!=None))
tmp= XkbAtomGetString(vmodNames[ndx]);
- if (tmp==NULL)
- sprintf(tmp=numBuf,"%d",ndx);
+ if (tmp==NULL) {
+ sprintf(numBuf,"%d",ndx);
+ tmp = numBuf;
+ }
len= strlen(tmp)+1;
if (format==XkbCFile)
diff --git a/xkb/xkmread.c b/xkb/xkmread.c
index a6fdc6faf..dc8ab612d 100644
--- a/xkb/xkmread.c
+++ b/xkb/xkmread.c
@@ -51,7 +51,7 @@ XkbInternAtom(char *str,Bool only_if_exists)
}
char *
-_XkbDupString(char *str)
+_XkbDupString(const char *str)
{
char *new;