From: Christophe CURIS <christophe.cu...@free.fr> When a function is used as a call-back, it is dangerous to have arguments with a type different than what is expected by the call-back definition.
This patch sets the argument list to match what is expected by the call-back prototype and inserts an explicit type conversion at the beginning of the function. --- WINGs/hashtable.c | 18 ++++++++++-------- WINGs/memory.c | 2 +- WINGs/proplist.c | 14 ++++++-------- WINGs/wevent.c | 8 +++++--- WINGs/wlist.c | 5 ++++- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/WINGs/hashtable.c b/WINGs/hashtable.c index aec4f5a..bf4ea7b 100644 --- a/WINGs/hashtable.c +++ b/WINGs/hashtable.c @@ -35,8 +35,9 @@ typedef struct W_HashTable { #define RELKEY(table, key) if ((table)->callbacks.releaseKey) \ (*(table)->callbacks.releaseKey)(key) -static inline unsigned hashString(const char *key) +static inline unsigned hashString(const void *param) { + const char *key = param; unsigned ret = 0; unsigned ctr = 0; @@ -400,13 +401,14 @@ Bool WMNextHashEnumeratorItemAndKey(WMHashEnumerator * enumerator, void **item, return False; } -static Bool compareStrings(const char *key1, const char *key2) +static Bool compareStrings(const void *param1, const void *param2) { + const char *key1 = param1; + const char *key2 = param2; + return strcmp(key1, key2) == 0; } -typedef unsigned (*hashFunc) (const void *); -typedef Bool(*isEqualFunc) (const void *, const void *); typedef void *(*retainFunc) (const void *); typedef void (*releaseFunc) (const void *); @@ -418,15 +420,15 @@ const WMHashTableCallbacks WMIntHashCallbacks = { }; const WMHashTableCallbacks WMStringHashCallbacks = { - (hashFunc) hashString, - (isEqualFunc) compareStrings, + hashString, + compareStrings, (retainFunc) wstrdup, (releaseFunc) wfree }; const WMHashTableCallbacks WMStringPointerHashCallbacks = { - (hashFunc) hashString, - (isEqualFunc) compareStrings, + hashString, + compareStrings, NULL, NULL }; diff --git a/WINGs/memory.c b/WINGs/memory.c index e996e0d..7f4f0a8 100644 --- a/WINGs/memory.c +++ b/WINGs/memory.c @@ -52,7 +52,7 @@ static void defaultHandler(int bla) exit(1); } -static waborthandler *aborthandler = (waborthandler *) defaultHandler; +static waborthandler *aborthandler = defaultHandler; #define wAbort(a) (*aborthandler)(a) diff --git a/WINGs/proplist.c b/WINGs/proplist.c index 5c5242d..49cc53f 100644 --- a/WINGs/proplist.c +++ b/WINGs/proplist.c @@ -47,7 +47,7 @@ typedef struct StringBuffer { int size; } StringBuffer; -static unsigned hashPropList(WMPropList * plist); +static unsigned hashPropList(const void *param); static WMPropList *getPLString(PLData * pldata); static WMPropList *getPLQString(PLData * pldata); static WMPropList *getPLData(PLData * pldata); @@ -55,16 +55,13 @@ static WMPropList *getPLArray(PLData * pldata); static WMPropList *getPLDictionary(PLData * pldata); static WMPropList *getPropList(PLData * pldata); -typedef unsigned (*hashFunc) (const void *); typedef Bool(*isEqualFunc) (const void *, const void *); -typedef void *(*retainFunc) (const void *); -typedef void (*releaseFunc) (const void *); static const WMHashTableCallbacks WMPropListHashCallbacks = { - (hashFunc) hashPropList, + hashPropList, (isEqualFunc) WMIsPropListEqualTo, - (retainFunc) NULL, - (releaseFunc) NULL + NULL, + NULL }; static Bool caseSensitive = True; @@ -102,8 +99,9 @@ static Bool caseSensitive = True; #define MaxHashLength 64 -static unsigned hashPropList(WMPropList * plist) +static unsigned hashPropList(const void *param) { + WMPropList *plist= (WMPropList *) param; unsigned ret = 0; unsigned ctr = 0; const char *key; diff --git a/WINGs/wevent.c b/WINGs/wevent.c index 80bde8f..71be3d7 100644 --- a/WINGs/wevent.c +++ b/WINGs/wevent.c @@ -80,10 +80,12 @@ void WMCreateEventHandler(WMView * view, unsigned long mask, WMEventProc * event static int matchHandler(const void *item, const void *cdata) { -#define H1 ((W_EventHandler*)item) -#define H2 ((W_EventHandler*)cdata) + const W_EventHandler *h1 = item; + const W_EventHandler *h2 = cdata; - return (H1->eventMask == H2->eventMask && H1->proc == H2->proc && H1->clientData == H2->clientData); + return ((h1->eventMask == h2->eventMask) && + (h1->proc == h2->proc) && + (h1->clientData == h2->clientData)); } /* diff --git a/WINGs/wlist.c b/WINGs/wlist.c index 625b4bb..f15e900 100644 --- a/WINGs/wlist.c +++ b/WINGs/wlist.c @@ -635,7 +635,10 @@ static void handleEvents(XEvent * event, void *data) static int matchTitle(const void *item, const void *title) { - return (strcmp(((WMListItem *) item)->text, (const char *)title) == 0 ? 1 : 0); + const WMListItem *wl_item = item; + const char *s_title = title; + + return (strcmp(wl_item->text, s_title) == 0 ? 1 : 0); } int WMFindRowOfListItemWithTitle(WMList * lPtr, const char *title) -- 1.7.10.4 -- To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.