如果这是一个重复的帖子,很抱歉.
我目前遇到了一个问题,我收到关于这段代码的警告,显示为C6386: Buffer overrun while writing to 'titleTextPointer'
,但我相当确定运行时不会有缓冲区(假设所有标题都以'\0'
结尾):
const char *title = "test";
int titleLen = 0;
while (title[titleLen] != '\0') {
titleLen++;
}
WCHAR *titleTextPointer = (WCHAR *)malloc(sizeof(WCHAR) * (titleLen + 1)); //creates a new wide char list(WCHAR array) +1 for a terminating character(\0)
if (titleTextPointer == NULL) {
printf("error occured while locating space\n");
return 1;
}
for (int i = 0; i < titleLen; i++) { //iterates through lists and transfers memory
titleTextPointer[i] = title[i]; //actual transfer (char is 1byte, wide char is 2 bytes)
}
titleTextPointer[titleLen] = '\0'; //adds the last terminating value to properly use the widechar in function
我已try 分配更多空间(+2),但仍弹出警告.