[PATCH 08/25] Constify string for authorization protocol names

Alan Coopersmith alan.coopersmith at oracle.com
Sun Dec 11 10:16:21 PST 2011


gcc was warning from storing string constants in a char *name field:
auth.c:64:1: warning: initialization discards qualifiers from pointer target type
auth.c:72:1: warning: initialization discards qualifiers from pointer target type
auth.c:81:1: warning: initialization discards qualifiers from pointer target type

Making the field const requires changing AuthorizationFromID to take
a const char ** pointer for the name argument which it sets to point
to the matching name entry.

Changing that argument requires changing its sole caller in the security
extension to pass the address of a const char * variable to it, which it
can do, since the only thing it does with the returned name is to pass
it back to the RemoveAuthorization function that already expects a const
char *name.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 Xext/security.c |    3 ++-
 include/os.h    |    2 +-
 os/auth.c       |    4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/Xext/security.c b/Xext/security.c
index 6fc1eaf..63892aa 100644
--- a/Xext/security.c
+++ b/Xext/security.c
@@ -171,7 +171,8 @@ SecurityDeleteAuthorization(
 {
     SecurityAuthorizationPtr pAuth = (SecurityAuthorizationPtr)value;
     unsigned short name_len, data_len;
-    char *name, *data;
+    const char *name;
+    char *data;
     int status;
     int i;
     OtherClientsPtr pEventClient;
diff --git a/include/os.h b/include/os.h
index 1fd5367..0b50241 100644
--- a/include/os.h
+++ b/include/os.h
@@ -405,7 +405,7 @@ extern _X_EXPORT void InitAuthorization(char * /*filename*/);
 extern _X_EXPORT int AuthorizationFromID (
 	XID 		id,
 	unsigned short	*name_lenp,
-	char		**namep,
+	const char	**namep,
 	unsigned short	*data_lenp,
 	char		**datap);
 
diff --git a/os/auth.c b/os/auth.c
index 7685751..9d36249 100644
--- a/os/auth.c
+++ b/os/auth.c
@@ -48,7 +48,7 @@ from The Open Group.
 
 struct protocol {
     unsigned short   name_length;
-    char    *name;
+    const char         *name;
     AuthAddCFunc	Add;	/* new authorization data */
     AuthCheckFunc	Check;	/* verify client authorization data */
     AuthRstCFunc	Reset;	/* delete all authorization data entries */
@@ -236,7 +236,7 @@ int
 AuthorizationFromID (
 	XID 		id,
 	unsigned short	*name_lenp,
-	char		**namep,
+	const char	**namep,
 	unsigned short	*data_lenp,
 	char		**datap)
 {
-- 
1.7.3.2



More information about the xorg-devel mailing list