Fix strict-aliasing issue in X11 dynamic loader. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Wed, 16 Nov 2011 21:10:03 -0500
branchSDL-1.2
changeset 6082 3d4488ae2e24
parent 6081 895486678126
child 6083 5f85dce0d4fc
Fix strict-aliasing issue in X11 dynamic loader. Fixes dozens of compiler warnings on FreeBSD.
src/video/x11/SDL_x11dyn.c
--- a/src/video/x11/SDL_x11dyn.c	Wed Nov 16 05:20:17 2011 -0500
+++ b/src/video/x11/SDL_x11dyn.c	Wed Nov 16 21:10:03 2011 -0500
@@ -61,27 +61,30 @@
     { NULL, SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR },
 };
 
-static void X11_GetSym(const char *fnname, int *rc, void **fn)
+static void *X11_GetSym(const char *fnname, int *rc)
 {
+	void *fn = NULL;
 	int i;
 	for (i = 0; i < SDL_TABLESIZE(x11libs); i++) {
 		if (x11libs[i].lib != NULL)
 		{
-			*fn = SDL_LoadFunction(x11libs[i].lib, fnname);
-			if (*fn != NULL)
+			fn = SDL_LoadFunction(x11libs[i].lib, fnname);
+			if (fn != NULL)
 				break;
 		}
 	}
 
 	#if DEBUG_DYNAMIC_X11
-	if (*fn != NULL)
+	if (fn != NULL)
 		printf("X11: Found '%s' in %s (%p)\n", fnname, x11libs[i].libname, *fn);
 	else
 		printf("X11: Symbol '%s' NOT FOUND!\n", fnname);
 	#endif
 
-	if (*fn == NULL)
+	if (fn == NULL)
 		*rc = 0;  /* kill this module. */
+
+	return fn;
 }
 
 
@@ -158,14 +161,17 @@
 			}
 		}
 		#define SDL_X11_MODULE(modname) thismod = &SDL_X11_HAVE_##modname;
-		#define SDL_X11_SYM(a,fn,x,y,z) X11_GetSym(#fn,thismod,(void**)&p##fn);
+		#define SDL_X11_SYM(rc,fn,params,args,ret) \
+            p##fn = (rc(*)params) X11_GetSym(#fn, thismod);
 		#include "SDL_x11sym.h"
 		#undef SDL_X11_MODULE
 		#undef SDL_X11_SYM
 
 		#ifdef X_HAVE_UTF8_STRING
-		X11_GetSym("XCreateIC",&SDL_X11_HAVE_UTF8,(void **)&pXCreateIC);
-		X11_GetSym("XGetICValues",&SDL_X11_HAVE_UTF8,(void **)&pXGetICValues);
+		pXCreateIC = (XIC(*)(XIM,...)) X11_GetSym("XCreateIC",
+		                                          &SDL_X11_HAVE_UTF8);
+		pXGetICValues = (char * (*)(XIC,...)) X11_GetSym("XGetICValues",
+		                                                 &SDL_X11_HAVE_UTF8);
 		#endif
 
 		if (SDL_X11_HAVE_BASEXLIB) {  /* all required symbols loaded. */