From: Jack on
PBYTE binfile = new BYTE[size.QuadPart+0x1e0-4];

//
delete binfile;
binfile = NULL;

These statements are located in the same method.
What would be the probable causes of heap corruption
(written past the end of the heap buffer, buffer overrun i guess)
Thanks
Jack


From: Jack on
One might ask why I used new BYTE[...];
instead of std::vector<BYTE>

because I want to advance the pointer at my own will
such as this
binfile += 0x1e0;

binfile.push_back(....)
where ... is of type "static BYTE" also feeds back with errors.

Thanks
Jack



From: Jochen Kalmbach [MVP] on
Hi Jack!
> PBYTE binfile = new BYTE[size.QuadPart+0x1e0-4];
>
> These statements are located in the same method.
> What would be the probable causes of heap corruption
> (written past the end of the heap buffer, buffer overrun i guess)

You write beyond the allocated length...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
From: Jack on
> You write beyond the allocated length...

Thanks Jochen,
To hardcode (experiment) this, I have actually "rewind"
the pointer to the start of the buffer, then issue "delete binfile" to no
avail.
How can I specify the size of deletion? it seems that I can't have any
control of the deletion anyway...

Thanks
Jack


From: Jochen Kalmbach [MVP] on
Hi Jack!
>> You write beyond the allocated length...
>
> To hardcode (experiment) this, I have actually "rewind"
> the pointer to the start of the buffer, then issue "delete binfile" to no
> avail.

????
You *must* pass the *same* point to "delete" which was the result of the
"new" allocation!

> How can I specify the size of deletion? it seems that I can't have any
> control of the deletion anyway...

The previous allocated size will be freed... no need to specify anything...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 |  Next  |  Last
Pages: 1 2 3 4 5 6
Prev: Function vs Method
Next: C-type casting