Debug assertion fail!


Iam getting this error msg



Debug assertion Failed!

program:
c:\users\blablabla

Expresion:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

For information on how your program can cause an assertion
failure, see the visual c++ documentation on asserts

(press rety to debug the apllication)


I appreciate any help.
If you build with debug information included, it should tell you the line of your code that leads to this assertion failing.

However, that might not be enough, because this error indicates that at some point you are writing over some memory that you shouldn't be, and you're destroying some information the compiler put there to keep track of memory that was allocated by new, and this error only arises when it goes looking for that data, only to find that you've trashed it.

Last edited on
Are you sure that pHead is pointing to allocated memory?
#ifndef SEQUENCE_H
#define SEQUENCE_H
#include <cstdlib> // Provides size_t
#include <cassert>

namespace CISP430_A2
{
class sequence
{
public:
// TYPEDEFS and MEMBER CONSTANTS
typedef double value_type;
typedef size_t size_type;
enum { CAPACITY = 30 };
// CONSTRUCTOR
sequence(size_type entry=CAPACITY );//done
// COPY CONSTRUCTOR
sequence(const sequence& entry); //done
// Library facilities used: cstdlib
// MODIFICATION MEMBER FUNCTIONS
void start( );//done
void advance( );//done
void insert(const value_type& entry); //done
void attach(const value_type& entry);
void remove_current( );//done
void resize(size_type );//done
void sequence::operator =(const sequence&);//done
// CONSTANT MEMBER FUNCTIONS
size_type size() const;//done but not sure
bool is_item( ) const;//done
value_type current( ) const;//done
//Destructor
~sequence() ;//done
private:
value_type *data; // pointer to dynamic array
size_type used; //how much of array is being used
size_type capacity; //current capacity of the bag
size_type current_index;
};
}

#endif



#include <cctype> // Provides toupper
#include <iostream> // Provides cout and cin
#include <cstdlib> // Provides EXIT_SUCCESS
#include "sequence2.h" // With value_type defined as double
#include <cassert>
using namespace std;
using namespace CISP430_A2;

namespace CISP430_A2
{
sequence::sequence (size_type entry) //the default constructor, entry tells how many items to allocate for the dynamic array
{
data = new value_type[entry];//193
capacity = entry;
used = 0;
current_index = 0;
}


sequence::sequence(const sequence& entry) // the amount of memory allocated for entry determines how much memory to allocate for the new dynamic array
{
data = new value_type[entry.capacity];
current_index = entry.current_index;
capacity = entry.capacity; //193
used = entry.used;
copy (entry.data , entry.data + used , data);
}



void sequence::start()
{
current_index = 0;
}



void sequence::advance()
{
if (is_item())
current_index++;
}



void sequence::insert(const value_type& entry)//194
{
used ++;
if (used == capacity)
resize(used*1.1); //resizing by 10%
*(data+current_index) = entry;
cout << "\n insert value " << *(data+current_index) << " is the index " << current_index<< endl;
used = used*1.1;
advance();
}

void sequence::attach(const value_type& entry)
{

if(!(size()<capacity))
{
capacity=(capacity*1.1)+1;
resize(capacity);
data[current_index+1]=entry;
}

if(!is_item())
{
data[current_index]=entry;
}
else
{
for (int i=used; current_index<i; i--)
{
data[i]=data[i-1];
}
data[current_index+1]=entry;
current_index++;
}
++used;

}






void sequence::remove_current()
{
size_type temp = used-1;
assert (is_item() == true);
if(used == 1)
used--;
else if (current_index == temp)
{ used --;
current_index--;
}
else if (current_index < temp)
{
for(int k = current_index; k < temp; k++)
data[k] = data[k+1];

used--;
}
}



void sequence::resize(size_type new_capacity)//193
{
value_type* larger_array;

if (new_capacity == capacity)
return; //the allocated memory is already the right size

if (new_capacity < used)
new_capacity = used; //cant allocate less than we are using

larger_array = new value_type[new_capacity];
copy(data, data + used, larger_array);
delete [] data;
data = larger_array;
capacity = new_capacity;
}




void sequence::operator =(const sequence& entry)//190
{
current_index = entry.current_index;
value_type* new_data;
if (this == &entry)
return;
if (capacity != entry.capacity)
{
new_data = new value_type[entry.capacity];
delete [] data;
data = new_data;
capacity = entry.capacity;
}
used = entry.used;
copy(entry.data, entry.data + used, data);
}



sequence::size_type sequence::size( ) const
{
return used;
}



bool sequence::is_item( ) const
{
if ( current_index < used)
return true;
else
return false;
}



sequence::value_type sequence::current() const
{
assert(current_index < capacity);
return data[current_index];
}

sequence::~sequence() //destructor, deallocate memory of data
{
delete [] data; //193
}


}





'A2.exe': Loaded 'C:\Users\MONA\Documents\cisp430\projects\A2\Debug\A2.exe', Symbols loaded.
'A2.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Program Files\BitDefender\BitDefender 2011\Active Virus Control\Midas_00087_015\midas32.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Program Files\BitDefender\BitDefender 2011\Active Virus Control\Midas_00087_015\plugin_base.m32', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Program Files\BitDefender\BitDefender 2011\Active Virus Control\Midas_00087_015\plugin_nt.m32', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Program Files\BitDefender\BitDefender 2011\Active Virus Control\Midas_00087_015\plugin_registry.m32', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Program Files\BitDefender\BitDefender 2011\Active Virus Control\Midas_00087_015\plugin_extra.m32', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Program Files\BitDefender\BitDefender 2011\Active Virus Control\Midas_00087_015\plugin_net.m32', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Program Files\BitDefender\BitDefender 2011\Active Virus Control\Midas_00087_015\plugin_fragments.m32', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded.
'A2.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded.
'A2.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Program Files\BitDefender\BitDefender 2011\Antispam32\pchook32.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\shell32.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_50934f2ebcb7eb57\msvcr90.dll', Cannot find or open the PDB file
'A2.exe': Loaded 'C:\Windows\SysWOW64\profapi.dll', Cannot find or open the PDB file
The thread 'Win32 Thread' (0x20a4) has exited with code -1073741510 (0xc000013a).
The thread 'Win32 Thread' (0x2010) has exited with code -1073741510 (0xc000013a).
The thread 'Win32 Thread' (0x21cc) has exited with code -1073741510 (0xc000013a).
The program '[7300] A2.exe: Native' has exited with code -1073741510 (0xc000013a).
Now im getting this:

windows has triggered a breakingpoint in A@.exe

this may be due to a corruption of the heap, which indicates a bug in A2.exe or any of the DLLs it has loaded

this may also be due to the user pressing f12 while A2.exe has focus

the output window may have more diagnostic information


in different window



unhandled exception at 0x7776e6c3 in A2.exe 0xc000374: A heap has been corrupted
Last edited on
Give us minimal code that demonstrates the problem - something we can follow from the start of main.

It's a shame you're running under windows; if you could use valgrind, this would be cleared up very quickly.
In your code, it is possible for the member used to be equal to capacity in the normal course of events. See sequence::attach.

Inspect sequence::insert and see how that might be a problem. Also, note that (aside from the atrocious use of doubles to scale your sizes) you're effectively setting used in that function to capacity which kind of makes increasing capacity by 10% pointless.
Topic archived. No new replies allowed.