Ada*_*ile 4 c c++ memory windows-mobile
在调用时,我的一些代码中出现了一些奇怪的,间歇性的数据中止(<5%的时间)memset().问题是,除非代码运行了几天,否则通常不会发生,因此很难在行为中捕获它.
我正在使用以下代码:
char *msg = (char*)malloc(sizeof(char)*2048);
char *temp = (char*)malloc(sizeof(char)*1024);
memset(msg, 0, 2048);
memset(temp, 0, 1024);
char *tempstr = (char*)malloc(sizeof(char)*128);
sprintf(temp, "%s %s/%s %s%s", EZMPPOST, EZMPTAG, EZMPVER, TYPETXT, EOL);
strcat(msg, temp);
//Add Data
memset(tempstr, '\0', 128);
wcstombs(tempstr, gdevID, wcslen(gdevID));
sprintf(temp, "%s: %s%s", "DeviceID", tempstr, EOL);
strcat(msg, temp);
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,我并没有尝试使用尺寸大于最初分配的memset malloc()
有人看到这可能有什么问题吗?
Joe*_*sky 21
mallocNULL如果没有可用的内存,则可以返回 你没有检查.