[ddraw] DD_STRUCT_COPY_BYSIZE

Peter Berg Larsen pebl at math.ku.dk
Mon Oct 17 18:16:25 CDT 2005


No one complained about how the macro should behave in the last email, so 
here it is:

Changelog:
 	memcpy could copy too much if from->dwSize is too big.
 	Only memset what is needed.

Index: dlls/ddraw/ddraw_private.h
===================================================================
RCS file: /home/wine/wine/dlls/ddraw/ddraw_private.h,v
retrieving revision 1.51
diff -p -u -r1.51 ddraw_private.h
--- dlls/ddraw/ddraw_private.h	10 Oct 2005 19:53:37 -0000	1.51
+++ dlls/ddraw/ddraw_private.h	17 Oct 2005 22:45:23 -0000
@@ -41,19 +41,22 @@
  		(x)->dwSize = sizeof(*x);	\
  	} while (0)

-#define DD_STRUCT_COPY_BYSIZE(to,from)			\
-	do {						\
-	    	DWORD __size = (to)->dwSize;		\
-	    	DWORD __copysize = __size;		\
-	    	DWORD __resetsize = __size;		\
-		assert(to != from);                     \
-	        if (__resetsize > sizeof(*to))		\
-		    __resetsize = sizeof(*to);		\
-	    	memset(to,0,__resetsize);               \
-	        if ((from)->dwSize < __size) 		\
-		    __copysize = (from)->dwSize;	\
-		memcpy(to,from,__copysize);		\
-		(to)->dwSize = __size;/*restore size*/	\
+/* Se bug 2070 regarding the sizeofs. */
+#define DD_STRUCT_COPY_BYSIZE(to,from)					\
+	do {								\
+	    	DWORD __tosize1  = (to)->dwSize;			\
+	    	DWORD __tosize2  = (to)->dwSize;			\
+	    	DWORD __copysize = (from)->dwSize;			\
+		assert((to) != (from));                     		\
+		if (sizeof(*(to)) < __tosize2) 				\
+		    __tosize2  = sizeof(*(to)); 			\
+		if (__tosize2 < __copysize)			 	\
+		    __copysize = __tosize2; 				\
+		if (sizeof(*(from)) < __copysize)		 	\
+		    __copysize = sizeof(*(from)); 			\
+		memcpy((to),(from),__copysize);				\
+	    	memset(((char *)to)+__copysize,0,__tosize2-__copysize);	\
+		(to)->dwSize = __tosize1;/*restore size*/		\
  	} while (0)

  #define MAKE_FOURCC(a,b,c,d) ((a << 0) | (b << 8) | (c << 16) | (d << 24))



More information about the wine-patches mailing list