Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / C++ : _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

Author
Message
Thoth Onegan
20
Years of Service
User Offline
Joined: 21st Apr 2004
Location: Devhat
Posted: 17th Aug 2004 12:24
I am working on a VC++ 6.0 program. For some reason I keep getting this assert error.

Program : SERVER.EXE
File : dbgdel.cpp
Line : 47

Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

I looked around and it seems to be caused by one of three main things:
1) Deleting data from a DLL allocated in a EXE.
2) Accessing past the arrays allocated amount.
3) Trying to delete an array without the [] on the delete.

Here is the code for the lifetime of the varible:


The assertion error is caused by the last line. All SQL_QUERY does is use a DLL to query a SQL database. It is not affecting temp_select at all.

Any ideas on what the problem is?

I seek the Codemaster Talon.
Ilya
21
Years of Service
User Offline
Joined: 10th Aug 2003
Location:
Posted: 17th Aug 2004 14:55
Quote: "_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)"

Doesn't that mean that there is no error?
"IS_VALID"
(I don't know anything about c++)

-Ilya
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Aug 2004 16:27
You are exceeding the buffer size and writing into memory you have not allocated.

You allocate 39 bytes, and then zero this many:

37+1+strlen(verification_msg->username)+1+16+1+strlen(verification_msg->password)+1+5

That comes to 52 characters + the username and password lengths. Watch your buffers.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Thoth Onegan
20
Years of Service
User Offline
Joined: 21st Apr 2004
Location: Devhat
Posted: 18th Aug 2004 04:11 Edited at: 18th Aug 2004 06:21
Isnt it zeroing message though not temp_select?
Ill check the allocation for message when i get home, would overflowing message cause an error when deleting temp_select?

Edit> message is allocated the same amount as im zeroing.


Here is much simpler code that caused the same problem.


I seek the Codemaster Talon.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Aug 2004 06:30
Oops, yep ...

Deleting memory from a DLL will cause the separate heaps (from your EXE and DLL) to corrupt each other, which would cause something like this.

If that is not the case (you are not using a DLL, or not passing memory between them), then you are overwriting the buffer somewhere - that's what the check is for.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Powersoft
21
Years of Service
User Offline
Joined: 1st Aug 2003
Location: United Kingdom
Posted: 18th Aug 2004 06:40
what does this do?


Create or Play? You choose!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 18th Aug 2004 06:58
Doh. I've just spotted the problem. You can't do this:



Firstly, you don't need to allocate memory to hold a literal temporary string. This would do:



Secondly, you cannot delete a literal string.

This fixed code should do the job:



*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins, source and the Interface library for Visual C++ 6, .NET and now for Dev-C++ http://www.matrix1.demon.co.uk
Thoth Onegan
20
Years of Service
User Offline
Joined: 21st Apr 2004
Location: Devhat
Posted: 18th Aug 2004 11:08
Ah I see, then when I leave the function itll automatically clean up.

Thanks a lot.

I seek the Codemaster Talon.

Login to post a reply

Server time is: 2024-09-22 10:37:58
Your offset time is: 2024-09-22 10:37:58