Prev: Function vs Method
Next: C-type casting
From: Jack on 16 Dec 2009 07:48 Hi Igor, Thanks for your help first! I've posted the whole method under Jochen's post :) Could you please cross-check the coding for me? Under jochen's post... Thanks Jack
From: Igor Tandetnik on 16 Dec 2009 08:04 Jack wrote: > I've posted the whole method under Jochen's post :) > Could you please cross-check the coding for me? It has the exact same problem. Plus the fact that you are no longer doing "new" (delegating to vector to perform the allocation), but are still doing "delete" (on the pointer that you didn't allocate). -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Jack on 16 Dec 2009 08:12 Hello Igor, I hv deleted the "delete binfile" line,but still buffer overrun Thanks Jack
From: Igor Tandetnik on 16 Dec 2009 08:50 Jack wrote: > I hv deleted the "delete binfile" line,but still > buffer overrun Because you are still writing past the end of allocated buffer. std::vector< BYTE > v( size.QuadPart+0x1e0-4 ); memset (binfile, 0, size.QuadPart+0x1e4-4); Note 0x1e0 in the first line, 0x1e4 in the second. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Stephen Howe on 16 Dec 2009 09:28
>> Actually, I have tried both delete and delete[], but doesn't work either. > >In this special case (POD) it makes no difference... Oh yes it does. POD'ness does not come into it. Yes I know there is no destructors delete [] retrieves the number of items delete does not. It is perfectly possible, depending on implementation, that this screws up the heap. The number of items has been implemented by overallocation of memory blocks but it has also been implemented by associative arrays. Using delete could cause some non-cleanup of bookkeeping for delete []. Stephen Howe |