“CRT 检测到应用程序写入堆缓冲区的内存末尾”错误。它到达时崩溃free
。任何帮助表示赞赏。
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:")] = '\0';
strncpy(messageContent,
cPtr + strlen("Content:"),
strlen(cPtr + strlen("Content:")));
...
free(messageSubject);
free(messageContent);
}
void main() {
char* message = "Subject:HelloWorldContent:MessageContent";
int result = messageFunction(message);
}