Monday, August 26, 2019

c++ - crt detected that the application wrote to memory after end of heap buffer

Answer


char* SequenceTokenAnalizer::NextToken(char delim)
{




int main()
{
SequenceTokenAnalizer st1("This is a test");
char* helpSequence;
helpSequence = st1.NextToken();
cout << helpSequence << endl;
delete[] helpSequence;
}

int i = currentindex, i2 = currentindex, cnt = 0, j = 0;

char *token=NULL;

if (Sequence[i2] == delim)
{
while (Sequence[i2] == delim&& Sequence[i2] != '\0')
{
i2++;

}
while (Sequence[i2] != delim&& Sequence[i2]!='\0')

{
cnt++;
i2++;
}
token = new char[cnt];
if (Sequence[i] == delim)
{
while (Sequence[i] == delim)
{
i++;


}
while (Sequence[i] != delim&& Sequence[i2] != '\0')
{
token[j] = Sequence[i];
i++;
j++;
}
token[j] = '\0';
currentindex = i;

return token;
}
}
else
{
while (Sequence[i2] != delim)
{
cnt++;
i2++;
}

token = new char[cnt];


if (Sequence[i] == delim)
{
while (Sequence[i] == delim)
{
i++;

}

while (Sequence[i] != delim)
{
token[j] = Sequence[i];
i++;
j++;
}
token[j] = '\0';
currentindex = i;
return token;
}

else
{
while (Sequence[i] != delim)
{
token[j] = Sequence[i];
i++;
j++;
}
token[j] = '\0';
currentindex = i;

return token;
}
}


class:



#include



#include




using namespace std;



const int SIZE = 80;



class SequenceTokenAnalizer {



char Sequence[SIZE];
char delimiter;
int currentindex;



public:



SequenceTokenAnalizer(char str[]);

SequenceTokenAnalizer(char str[], char delim);

int LengthSequence();


int CountAllTokens();
void ResetTokens();
int CountTokens();
bool HasMoreTokens();
bool HasMoreTokens(char delim);
char* NextToken();
char* NextToken(char delim);
bool Equals(SequenceTokenAnalizer other);
bool NotEquals(SequenceTokenAnalizer other);
bool isCommonToken(SequenceTokenAnalizer other);

void PrintCommonTokens(SequenceTokenAnalizer other);


};



after using delete[] in main I get crt detected that the application wrote to memory after end of heap buffer please helppppp here i have sequences and have to return next tokken from current index
after using delete[] in main I get crt detected that the application wrote to memory after end of heap buffer please helppppp here i have sequences and have to return next tokken from current index

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...