dlls/kernel32/task.c -- minor improvement

Gerald Pfeifer gerald at pfeifer.com
Thu Jan 3 15:46:56 CST 2008


This started out to fix a warning, but I believe it's a genuine 
improvement:

 - We used the magic constant 8 instead of 4*sizeof(WORD).
 - Having thunks[4] really isn't a good fit when the whole array is 
   generated dynamically when allocating the struct.
 - And indeed GCC 4.3 would warning about out-of-bound array access.

I know that at first sight this sounds scary, but it's really only three 
lines of a patch, very localized and surprisingly straightforward. ;-)

Gerald

ChangeLog:
Use 4*sizeof(WORD) instead of the magic constant 8 for THUNKS.thunks[]
and properly make the latter an open array instead of [4].

Index: dlls/kernel32/task.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel32/task.c,v
retrieving revision 1.2
diff -u -3 -p -r1.2 task.c
--- dlls/kernel32/task.c	13 Oct 2006 10:27:19 -0000	1.2
+++ dlls/kernel32/task.c	3 Jan 2008 21:33:44 -0000
@@ -57,7 +57,7 @@ typedef struct
     WORD  magic;      /* Thunks signature */
     WORD  unused;
     WORD  free;       /* Head of the free list */
-    WORD  thunks[4];  /* Each thunk is 4 words long */
+    WORD  thunks[];   /* Each thunk is 4 words long */
 } THUNKS;
 
 #include "poppack.h"
@@ -174,7 +174,7 @@ static void TASK_CreateThunks( HGLOBAL16
     free = pThunk->free;
     for (i = 0; i < count-1; i++)
     {
-        free += 8;  /* Offset of next thunk */
+        free += 4*sizeof(WORD);  /* Offset of next thunk */
         pThunk->thunks[4*i] = free;
     }
     pThunk->thunks[4*i] = 0;  /* Last thunk */
@@ -201,7 +201,8 @@ static SEGPTR TASK_AllocThunk(void)
         sel = pThunk->next;
         if (!sel)  /* Allocate a new segment */
         {
-            sel = GLOBAL_Alloc( GMEM_FIXED, sizeof(THUNKS) + (MIN_THUNKS-1)*8,
+            sel = GLOBAL_Alloc( GMEM_FIXED,
+                                sizeof(THUNKS) + MIN_THUNKS*4*sizeof(WORD),
                                 pTask->hPDB, WINE_LDT_FLAGS_CODE );
             if (!sel) return (SEGPTR)0;
             TASK_CreateThunks( sel, 0, MIN_THUNKS );



More information about the wine-patches mailing list