[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wine-patches
Subject:    cabinet: fully initialize structs in FCICreate() and FCIAddFile()
From:       "Dan Kegel" <dank () kegel ! com>
Date:       2007-10-31 6:23:06
Message-ID: a71bd89a0710302323u40f78c5byea4c4d2fc5915cc0 () mail ! gmail ! com
[Download RAW message or body]

The code seems to have missed initializing a field
in two structs, which causes warnings in Valgrind.

Rather than hunt it down precisely, I applied
the old "memset the struct to zero when allocating"
meme, which in some circles is considered the "right"
way to avoid this kind of problem.  (I halfway expect
Alexandre to say "don't be so lazy", but it's worth a try.)

-- 
Wine for Windows ISVs: http://kegel.com/wine/isv

["cabinet.patch" (text/x-patch)]

This patch makes the following two valgrind errors go away:

==6183== Syscall param write(buf) points to uninitialised byte(s)
==6183==    at 0x40007F2: (within /lib/ld-2.5.so)
==6183==    by 0x44E8B0D: WriteFile (file.c:512)
==6183==    by 0x45DE23A: fci_write (extract.c:182)
==6183==    by 0x45FE1B6: FCIAddFile (fci.c:2558)
==6183==    by 0x45DE47C: add_file (extract.c:269)
==6183==    by 0x45DEC2E: func_extract (extract.c:305)
==6183==    by 0x45E4827: run_test (test.h:387)
==6183==    by 0x45E4EBC: main (test.h:436)
==6183==  Address 0x7F22F866 is on thread 1's stack
==6183== 
==6183== Conditional jump or move depends on uninitialised value(s)
==6183==    at 0x45FA882: fci_flush_folder (fci.c:497)
==6183==    by 0x45FBCC1: fci_flush_cabinet (fci.c:1540)
==6183==    by 0x45FD73F: FCIFlushCabinet (fci.c:2789)
==6183==    by 0x45DEC79: func_extract (extract.c:310)
==6183==    by 0x45E4827: run_test (test.h:387)
==6183==    by 0x45E4EBC: main (test.h:436)

diff --git a/dlls/cabinet/fci.c b/dlls/cabinet/fci.c
index b5e6c9c..f99ceda 100644
--- a/dlls/cabinet/fci.c
+++ b/dlls/cabinet/fci.c
@@ -197,6 +197,7 @@ HFCI __cdecl FCICreate(
     return NULL;
   }
 
+  memset(hfci, 0, sizeof(FCI_Int));
   p_fci_internal=((PFCI_Int)(hfci));
   p_fci_internal->FCI_Intmagic = FCI_INT_MAGIC;
   p_fci_internal->perf = perf;
@@ -2378,6 +2379,7 @@ BOOL __cdecl FCIAddFile(
     return FALSE;
   }
 
+  memset(&cffile, 0, sizeof(cffile));
   cffile.cbFile=0; /* size of the to be added file*/
   /* offset of the uncompressed file in the folder */
   cffile.uoffFolderStart=p_fci_internal->cDataBlocks*CAB_BLOCKMAX + p_fci_internal->cdata_in;




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic