I'm getting the error:
HEAP CORRUPTION DETECTED: After Normal block (#247) at 0x003B98D0.
CRT detected that the application wrote to memory after end of heap buffer.
Here's the function that's causing the problem:
String ^data::getItemNumber_noRev()
{
int count = 0;
while(itemNumber[count] != '_')
count++;
char *itemNum_noRev = new char[count];
for(int i = 0; i < count; i++)
itemNum_noRev[i] = itemNumber[i];
itemNum_noRev[count] = '\0';
gcroot<String ^> itemNum_noRev_system = gcnew String(itemNum_noRev);
delete [] itemNum_noRev;
return itemNum_noRev_system;
}
Basically it goes through a char array such as 12324736-1_6, where everything up to the underscore is the item number, and after is its revision. It is returned as a System::String^ because I'm using it in a Windows Form. The problem I'm having is with the line:
itemNum_noRev[count] = '\0';
When I don't include this line, I don't get an error, but I get about 10 magic characters at the end of my String. When I do include the line, that's when I get the heap corruption error.
Any ideas what to do to fix this? Thanks in advance for any advice!
Pat