From f62ba192c285b1e49bf299f03fc0b763680afaaf Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Thu, 13 May 2010 01:47:26 +0700 Subject: [PATCH 1/9] Do not use deprecated Xalloc function Signed-off-by: Mikhail Gusarov Reviewed-by: Matt Turner --- mi/mipolypnt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mi/mipolypnt.c b/mi/mipolypnt.c index 3c6ed4eb8..5a0e52363 100644 --- a/mi/mipolypnt.c +++ b/mi/mipolypnt.c @@ -73,7 +73,7 @@ miPolyPoint( int i; xPoint *ppt; - if(!(pwidthInit = xalloc(npt * sizeof(int)))) + if(!(pwidthInit = malloc(npt * sizeof(int)))) return; /* make pointlist origin relative */ From ff2b4cf8329b1678adafcda02e5d47a072550d47 Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Thu, 13 May 2010 01:51:37 +0700 Subject: [PATCH 2/9] Turn sprintf argument into literaral string, shutting up gcc warning Signed-off-by: Mikhail Gusarov Reviewed-by: Matt Turner --- os/osinit.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/os/osinit.c b/os/osinit.c index e8fcd4540..32747df52 100644 --- a/os/osinit.c +++ b/os/osinit.c @@ -161,7 +161,6 @@ void OsInit(void) { static Bool been_here = FALSE; - static char* admpath = ADMPATH; static char* devnull = "/dev/null"; char fname[PATH_MAX]; @@ -229,8 +228,8 @@ OsInit(void) { FILE *err; - if (strlen (display) + strlen (admpath) + 1 < sizeof fname) - sprintf (fname, admpath, display); + if (strlen (display) + strlen (ADMPATH) + 1 < sizeof fname) + sprintf (fname, ADMPATH, display); else strcpy (fname, devnull); /* From 5a8e2f2745ae1f74501cd3f42614a1ed2cf974f2 Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Wed, 12 May 2010 18:54:51 +0000 Subject: [PATCH 3/9] Do not jump through the hoops to deallocate xkbbasedirflag variable Fixes gcc warning as well. Signed-off-by: Mikhail Gusarov Reviewed-by: Jamey Sharp Reviewed-by: Matt Turner --- xkb/ddxLoad.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/xkb/ddxLoad.c b/xkb/ddxLoad.c index a9b5ca984..b1d629436 100644 --- a/xkb/ddxLoad.c +++ b/xkb/ddxLoad.c @@ -186,7 +186,7 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb, char *buf = NULL, keymap[PATH_MAX], xkm_output_dir[PATH_MAX]; const char *emptystring = ""; - const char *xkbbasedirflag = emptystring; + char *xkbbasedirflag = NULL; const char *xkbbindir = emptystring; const char *xkbbindirsep = emptystring; @@ -230,13 +230,11 @@ XkbDDXCompileKeymapByNames( XkbDescPtr xkb, xkbbindir, xkbbindirsep, ( (xkbDebugFlags < 2) ? 1 : ((xkbDebugFlags > 10) ? 10 : (int)xkbDebugFlags) ), - xkbbasedirflag, xkmfile, + xkbbasedirflag ? xkbbasedirflag : "", xkmfile, PRE_ERROR_MSG, ERROR_PREFIX, POST_ERROR_MSG1, xkm_output_dir, keymap); - if (xkbbasedirflag != emptystring) { - free(xkbbasedirflag); - } + free(xkbbasedirflag); #ifndef WIN32 out= Popen(buf,"w"); From 868e372a73b377705217e0379bc6e00f36c4d8e5 Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Thu, 13 May 2010 01:59:06 +0700 Subject: [PATCH 4/9] Introduce X_NORETURN macro defined as __attribute__((noreturn)) for gcc Signed-off-by: Mikhail Gusarov Reviewed-by: Matt Turner --- include/misc.h | 6 ++++++ include/os.h | 5 +---- os/log.c | 5 ++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/include/misc.h b/include/misc.h index c7add253e..e4bdee480 100644 --- a/include/misc.h +++ b/include/misc.h @@ -106,6 +106,12 @@ typedef unsigned long ATOM; #define X_DEPRECATED #endif +#if defined(__GNUC__) && (__GNUC__ > 2) +#define X_NORETURN __attribute__((noreturn)) +#else +#define X_NORETURN +#endif + #ifndef _XTYPEDEF_CALLBACKLISTPTR typedef struct _CallbackList *CallbackListPtr; /* also in dix.h */ #define _XTYPEDEF_CALLBACKLISTPTR diff --git a/include/os.h b/include/os.h index 7f358eeaf..82d6694c2 100644 --- a/include/os.h +++ b/include/os.h @@ -547,10 +547,7 @@ extern _X_EXPORT void FreeAuditTimer(void); extern _X_EXPORT void AuditF(const char *f, ...) _printf_attribute(1,2); extern _X_EXPORT void VAuditF(const char *f, va_list args); extern _X_EXPORT void FatalError(const char *f, ...) _printf_attribute(1,2) -#if defined(__GNUC__) && (__GNUC__ > 2) -__attribute((noreturn)) -#endif -; + X_NORETURN; #ifdef DEBUG #define DebugF ErrorF diff --git a/os/log.c b/os/log.c index ff78545e1..078165985 100644 --- a/os/log.c +++ b/os/log.c @@ -402,9 +402,8 @@ LogMessage(MessageType type, const char *format, ...) va_end(ap); } -#ifdef __GNUC__ -void AbortServer(void) __attribute__((noreturn)); -#endif +void +AbortServer(void) X_NORETURN; void AbortServer(void) From 8b5326aa98eba201dd78aea3dd7114e1a084489b Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Wed, 12 May 2010 20:27:02 +0000 Subject: [PATCH 5/9] Mark OsAbort as noreturn function to make gcc happier. Signed-off-by: Mikhail Gusarov Reviewed-by: Matt Turner --- include/os.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/os.h b/include/os.h index 82d6694c2..d34e056ed 100644 --- a/include/os.h +++ b/include/os.h @@ -299,7 +299,7 @@ extern _X_EXPORT void OsBlockSignals (void); extern _X_EXPORT void OsReleaseSignals (void); -extern _X_EXPORT void OsAbort (void); +extern _X_EXPORT void OsAbort (void) X_NORETURN; #if !defined(WIN32) extern _X_EXPORT int System(char *); From 28211c443c693a1ca3db5740d0128274a3eef723 Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Thu, 13 May 2010 03:43:04 +0700 Subject: [PATCH 6/9] Fix warning: it's safe to pass atom strings > XA_LAST_PREDEFINED to free(3) Signed-off-by: Mikhail Gusarov Reviewed-by: Keith Packard --- dix/atom.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dix/atom.c b/dix/atom.c index ecfe4b0c7..6910dd5d1 100644 --- a/dix/atom.c +++ b/dix/atom.c @@ -180,8 +180,13 @@ FreeAtom(NodePtr patom) FreeAtom(patom->left); if(patom->right) FreeAtom(patom->right); - if (patom->a > XA_LAST_PREDEFINED) - free(patom->string); + if (patom->a > XA_LAST_PREDEFINED) { + /* + * All strings above XA_LAST_PREDEFINED are strdup'ed, so it's safe to + * cast here + */ + free((char *)patom->string); + } free(patom); } From 63a647abd51f44226cbd16aa04ebc57d07463c6d Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Thu, 13 May 2010 03:44:12 +0700 Subject: [PATCH 7/9] Fix code style: extra whitespace before () Signed-off-by: Mikhail Gusarov Reviewed-by: Keith Packard --- dix/atom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dix/atom.c b/dix/atom.c index 6910dd5d1..02843d233 100644 --- a/dix/atom.c +++ b/dix/atom.c @@ -213,5 +213,5 @@ InitAtoms(void) nodeTable[None] = (NodePtr)NULL; MakePredeclaredAtoms(); if (lastAtom != XA_LAST_PREDEFINED) - AtomError (); + AtomError(); } From 816b79dd061e9839cec94a4986a7820b70ca8a7f Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Thu, 13 May 2010 03:45:21 +0700 Subject: [PATCH 8/9] Remove useless casts Signed-off-by: Mikhail Gusarov Reviewed-by: Keith Packard --- dix/atom.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/dix/atom.c b/dix/atom.c index 02843d233..7d04c6833 100644 --- a/dix/atom.c +++ b/dix/atom.c @@ -68,7 +68,7 @@ typedef struct _Node { } NodeRec, *NodePtr; static Atom lastAtom = None; -static NodePtr atomRoot = (NodePtr)NULL; +static NodePtr atomRoot = NULL; static unsigned long tableLength; static NodePtr *nodeTable; @@ -88,7 +88,7 @@ MakeAtom(const char *string, unsigned len, Bool makeit) fp = fp * 27 + string[i]; fp = fp * 27 + string[len - 1 - i]; } - while (*np != (NodePtr) NULL) + while (*np != NULL) { if (fp < (*np)->fingerPrint) np = &((*np)->left); @@ -130,11 +130,12 @@ MakeAtom(const char *string, unsigned len, Bool makeit) if ((lastAtom + 1) >= tableLength) { NodePtr *table; - table = (NodePtr *) realloc(nodeTable, - tableLength * (2 * sizeof(NodePtr))); + table = realloc(nodeTable, tableLength * (2 * sizeof(NodePtr))); if (!table) { - if (nd->string != string) - free(nd->string); + if (nd->string != string) { + /* nd->string has been strdup'ed */ + free((char *)nd->string); + } free(nd); return BAD_RESOURCE; } @@ -142,7 +143,7 @@ MakeAtom(const char *string, unsigned len, Bool makeit) nodeTable = table; } *np = nd; - nd->left = nd->right = (NodePtr) NULL; + nd->left = nd->right = NULL; nd->fingerPrint = fp; nd->a = (++lastAtom); *(nodeTable+lastAtom) = nd; @@ -163,7 +164,7 @@ NameForAtom(Atom atom) { NodePtr node; if (atom > lastAtom) return 0; - if ((node = nodeTable[atom]) == (NodePtr)NULL) return 0; + if ((node = nodeTable[atom]) == NULL) return 0; return node->string; } @@ -193,12 +194,12 @@ FreeAtom(NodePtr patom) void FreeAllAtoms(void) { - if(atomRoot == (NodePtr)NULL) + if(atomRoot == NULL) return; FreeAtom(atomRoot); - atomRoot = (NodePtr)NULL; + atomRoot = NULL; free(nodeTable); - nodeTable = (NodePtr *)NULL; + nodeTable = NULL; lastAtom = None; } @@ -210,7 +211,7 @@ InitAtoms(void) nodeTable = malloc(InitialTableSize*sizeof(NodePtr)); if (!nodeTable) AtomError(); - nodeTable[None] = (NodePtr)NULL; + nodeTable[None] = NULL; MakePredeclaredAtoms(); if (lastAtom != XA_LAST_PREDEFINED) AtomError(); From 432cbbec194e47bf2a117c9302146e786c8a4ee1 Mon Sep 17 00:00:00 2001 From: Mikhail Gusarov Date: Thu, 13 May 2010 03:51:00 +0700 Subject: [PATCH 9/9] Misc coding style cleanup Use a[b] instead of *(a+b), fix whitespace. Signed-off-by: Mikhail Gusarov Reviewed-by: Keith Packard --- dix/atom.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dix/atom.c b/dix/atom.c index 7d04c6833..88b40db65 100644 --- a/dix/atom.c +++ b/dix/atom.c @@ -145,8 +145,8 @@ MakeAtom(const char *string, unsigned len, Bool makeit) *np = nd; nd->left = nd->right = NULL; nd->fingerPrint = fp; - nd->a = (++lastAtom); - *(nodeTable+lastAtom) = nd; + nd->a = ++lastAtom; + nodeTable[lastAtom] = nd; return nd->a; } else @@ -194,7 +194,7 @@ FreeAtom(NodePtr patom) void FreeAllAtoms(void) { - if(atomRoot == NULL) + if (atomRoot == NULL) return; FreeAtom(atomRoot); atomRoot = NULL; @@ -208,7 +208,7 @@ InitAtoms(void) { FreeAllAtoms(); tableLength = InitialTableSize; - nodeTable = malloc(InitialTableSize*sizeof(NodePtr)); + nodeTable = malloc(InitialTableSize * sizeof(NodePtr)); if (!nodeTable) AtomError(); nodeTable[None] = NULL;