"CRT detected that the application wrote to memory end of heap buffer" error. It crashes when it arrives to free
. Any help is appreciated.
int messageFunction(char* message) {
char* sPtr = strstr(message,"Subject:");
char* cPtr = strstr(message,"Content:");
char* messageSubject = (char*) malloc(cPtr - sPtr - strlen("Subject:"))
char* messageContent = (char*) malloc(strlen(cPtr + strlen("Content:")))
strncpy(messageSubject,
stPtr + strlen("Subject:"),
cPtr - sPtr - strlen("Subject:"));
messageSubject[cPtr - sPtr - strlen("Subject:")] = '';
strncpy(messageContent,
cPtr + strlen("Content:"),
strlen(cPtr + strlen("Content:")));
...
free(messageSubject);
free(messageContent);
}
void main() {
char* message = "Subject:HelloWorldContent:MessageContent";
int result = messageFunction(message);
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…