[Gtkradiant] Bug with libs/ddslib/ddslib.c lines 693 to 723 on 64 bit systems.

Branan Riley branan at gmail.com
Thu Mar 13 18:05:28 CDT 2008


Switching surface from a void pointer to an unsigned int seems to have
fixed the crashes and image corruption. I've also fixed some of the
DDS loading functions to use size_t instead of unsigned int when
casting to/from pointers.


Index: libs/ddslib.h
===================================================================
--- libs/ddslib.h (revision 204)
+++ libs/ddslib.h (working copy)
@@ -181,7 +181,7 @@
   };
   unsigned int      alphaBitDepth;
   unsigned int      reserved;
-  void           *surface;
+  unsigned int      surface;
   union
   {
      ddsColorKey_t  ckDestOverlay;
Index: libs/ddslib/ddslib.c
===================================================================
--- libs/ddslib/ddslib.c   (revision 204)
+++ libs/ddslib/ddslib.c   (working copy)
@@ -523,7 +523,7 @@
   for( y = 0; y < yBlocks; y++ )
   {
      /* 8 bytes per block */
-     block = (ddsColorBlock_t*) ((unsigned int) dds->data + y * xBlocks * 8);
+     block = (ddsColorBlock_t*) ((size_t) dds->data + y * xBlocks * 8);

      /* walk x */
      for( x = 0; x < xBlocks; x++, block++ )
@@ -569,7 +569,7 @@
   for( y = 0; y < yBlocks; y++ )
   {
      /* 8 bytes per block, 1 block for alpha, 1 block for color */
-     block = (ddsColorBlock_t*) ((unsigned int) dds->data + y * xBlocks * 16);
+     block = (ddsColorBlock_t*) ((size_t) dds->data + y * xBlocks * 16);

      /* walk x */
      for( x = 0; x < xBlocks; x++, block++ )
@@ -625,7 +625,7 @@
   for( y = 0; y < yBlocks; y++ )
   {
      /* 8 bytes per block, 1 block for alpha, 1 block for color */
-     block = (ddsColorBlock_t*) ((unsigned int) dds->data + y * xBlocks * 16);
+     block = (ddsColorBlock_t*) ((size_t) dds->data + y * xBlocks * 16);

      /* walk x */
      for( x = 0; x < xBlocks; x++, block++ )



On Thu, Mar 13, 2008 at 2:03 PM, Randy Reddig <ydnar at shaderlab.com> wrote:
> If the loaded struct has a size_t or void *, then replace it with an
>  int and handle it as a 32-bit integer.
>
>  Randy
>
>
>
>
>  On Mar 13, 2008, at 1:12 PM, Branan Riley wrote:
>
>  > Has anyone figured this out yet? I glanced over the code that
>  > determines width and height, and it looks OK to me.
>  >
>  > When the DDS data is loaded, how is it done? is it a chunk of memory
>  > that's cast to a ddsBuffer_t*? if so, the problem might be alignment
>  > issues caused by "void* surface" on line 184 of ddslib.h. Other than
>  > that, my cursory glance reveals nothing of use.
>  >
>  > On Thu, Jan 17, 2008 at 6:37 AM, Forest Hale
>  > <lordhavoc at ghdigital.com> wrote:
>  >> Jay Dolan wrote:
>  >>> Forest Hale wrote:
>  >>>>
>  >>>> All pointers are always the same size on a given architecture,
>  >>>> the bug is somewhere else (possibly in the dds width/height
>  >>>> reading for example?).
>  >>>>
>  >>>> Note that sizeof(size_t) is always equal to sizeof(void *),
>  >>>> size_t is the correct type to use when pointer-size integer
>  >>>> arithmetic is needed.
>  >>>>
>  >>>>
>  >>> I thought ptrdiff_t was recommended for such things.  Same-same,
>  >>> maybe?
>  >>
>  >> ptrdiff_t is not part of ANSI C, so you can't count on it existing,
>  >> if I recall correctly MSVS2005 lacks it but I may be thinking of
>  >> older versions.
>  >>
>  >> The other difference is that ptrdiff_t is signed, size_t is unsigned.
>  >>
>  >>
>  >> --
>  >> LordHavoc
>  >> Author of DarkPlaces Quake1 engine and mod
>  >> http://icculus.org/twilight/darkplaces/
>  >> "War does not prove who is right, it proves who is left." - Unknown
>  >> "Any sufficiently advanced technology is indistinguishable from a
>  >> rigged demo." - James Klass
>  >>
>  >>
>  >> _______________________________________________
>  >>
>  >>
>  >> Gtkradiant mailing list
>  >> Gtkradiant at zerowing.idsoftware.com
>  >> http://zerowing.idsoftware.com/cgi-bin/mailman/listinfo/gtkradiant
>  >>
>  >
>  > _______________________________________________
>  > Gtkradiant mailing list
>  > Gtkradiant at zerowing.idsoftware.com
>  > http://zerowing.idsoftware.com/cgi-bin/mailman/listinfo/gtkradiant
>
>
>  _______________________________________________
>  Gtkradiant mailing list
>  Gtkradiant at zerowing.idsoftware.com
>  http://zerowing.idsoftware.com/cgi-bin/mailman/listinfo/gtkradiant
>



More information about the Gtkradiant mailing list