Prevent crash from unaligned memory access on sparc64, etc. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Mon, 08 Sep 2008 07:33:05 +0000
branchSDL-1.2
changeset 4151cab9823cb55e
parent 4150 1019eb074a56
child 4152 39b9405d3cb6
Prevent crash from unaligned memory access on sparc64, etc.

Fixes Bugzilla #602. I suspect this will crash elsewhere if the system
actually had modelines to report, though.
src/video/Xext/Xxf86vm/XF86VMode.c
     1.1 --- a/src/video/Xext/Xxf86vm/XF86VMode.c	Thu Aug 07 20:55:45 2008 +0000
     1.2 +++ b/src/video/Xext/Xxf86vm/XF86VMode.c	Mon Sep 08 07:33:05 2008 +0000
     1.3 @@ -214,6 +214,12 @@
     1.4      return True;
     1.5  }
     1.6  
     1.7 +/* this is to prevent an unaligned memory write on CPUs that need that. */
     1.8 +static void zap_ptr(char *ptr, size_t size)
     1.9 +{
    1.10 +    memset(ptr, '\0', size);
    1.11 +}
    1.12 +
    1.13  Bool
    1.14  SDL_NAME(XF86VidModeGetModeLine)(dpy, screen, dotclock, modeline)
    1.15      Display* dpy;
    1.16 @@ -284,7 +290,7 @@
    1.17  	}
    1.18  	_XRead(dpy, (char*)modeline->private, modeline->privsize * sizeof(INT32));
    1.19      } else {
    1.20 -	modeline->private = NULL;
    1.21 +	zap_ptr((char *)&modeline->private, sizeof(modeline->private))
    1.22      }
    1.23      UnlockDisplay(dpy);
    1.24      SyncHandle();