Re: How to use Delete in right way
From: Pavel Lebedinsky (m_pll)
Date: 01/28/05
- Next message: Oleg Starodumov: "Re: How to use Delete in right way"
- Previous message: Oleg Starodumov: "Re: How to use Delete in right way"
- In reply to: Oleg Starodumov: "Re: How to use Delete in right way"
- Next in thread: Oleg Starodumov: "Re: How to use Delete in right way"
- Reply: Oleg Starodumov: "Re: How to use Delete in right way"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 28 Jan 2005 00:42:03 -0800
"Oleg Starodumov" wrote:
>> m_psText[iRow] = new char[strlen(str)];
>> strcpy(m_psText[i],str);
>
> This code corrupts the heap, because strlen returns the number of
> characters,
> excluding the terminating null. But strcpy will copy the string plus the
> terminating null,
> thus overwriting one character after allocated buffer.
>
> It is unlikely that this is the main reason of problems in the
> application,
> but should be addressed anyway. Btw, PageHeap should miss most of such
> problems,
> but Debug CRT should report them when the object is being deleted.
To be precise, pageheap will also detect this when the block
is deleted, unless the length of the block is a multiple of 8,
in which case you should get an access violation at the time of
corruption.
You can use /unaligned parameter with pageheap to force
it to always place the block exactly at the end of a page
but this breaks most non-trivial applications because win32 heap
is documented to have 8 byte alignment, and many apps depend
on this.
- Next message: Oleg Starodumov: "Re: How to use Delete in right way"
- Previous message: Oleg Starodumov: "Re: How to use Delete in right way"
- In reply to: Oleg Starodumov: "Re: How to use Delete in right way"
- Next in thread: Oleg Starodumov: "Re: How to use Delete in right way"
- Reply: Oleg Starodumov: "Re: How to use Delete in right way"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|