请大家帮忙看下下面的程序
每次运行到
memset(filebuf,0,sizeof(filebuf));//就出现下面的异常提示信息
server94.exe 中的 0x102308cf (msvcr80d.dll) 处未处理的异常: 0xC0000005: 写入位置 0x00000000 时发生访问冲突int RecvData(SOCKET sock,char *data,DWORD filesize)
{
//recive the pack with fileinfo
char temp[TRANS_LENGTH]={0};
int recvbyte=0,tempbyte=0;
char *filebuf=NULL;
filebuf=(char*)malloc(filesize);
if(filebuf=NULL)
{
printf("Cannot Allocation Space!");
return 0;//分配空间失败
}
memset(filebuf,0,sizeof(filebuf));//
while(recvbyte<filesize)
{
tempbyte=recv(sock,temp,TRANS_LENGTH,0);
recvbyte+=tempbyte;
strcat_s(filebuf,sizeof(filebuf),temp);
}
if(recvbyte==filesize)
{
strcpy_s(data,filesize,filebuf);
free(filebuf);
filebuf=NULL;
return 1;
}
else
return 0;
}
每次运行到
memset(filebuf,0,sizeof(filebuf));//就出现下面的异常提示信息
server94.exe 中的 0x102308cf (msvcr80d.dll) 处未处理的异常: 0xC0000005: 写入位置 0x00000000 时发生访问冲突int RecvData(SOCKET sock,char *data,DWORD filesize)
{
//recive the pack with fileinfo
char temp[TRANS_LENGTH]={0};
int recvbyte=0,tempbyte=0;
char *filebuf=NULL;
filebuf=(char*)malloc(filesize);
if(filebuf=NULL)
{
printf("Cannot Allocation Space!");
return 0;//分配空间失败
}
memset(filebuf,0,sizeof(filebuf));//
while(recvbyte<filesize)
{
tempbyte=recv(sock,temp,TRANS_LENGTH,0);
recvbyte+=tempbyte;
strcat_s(filebuf,sizeof(filebuf),temp);
}
if(recvbyte==filesize)
{
strcpy_s(data,filesize,filebuf);
free(filebuf);
filebuf=NULL;
return 1;
}
else
return 0;
}
解决方案 »
- 关于串口读写数据问题
- 如何创建不同风格的childframe
- 新手提问:如何在窗体上放置控件并手工设置到某个确定的位置及尺寸?
- 在VC6.0 中 的 MFC ClassWizard Automation 对应到 vc.net 2003 是什么????
- 我现在用 VC编写一个类似示波器的界面,现在想通过该界面实时显示采集到的波形,请问我该如何决定X坐标的值,即占空比
- 为何在windows下画线都画不直的,都是锯齿
- ########请大家关注这个问题:图标下载###########
- 在VC中怎么样把一个CHM文件,挂在它的帮助上面!谢谢大虾! ( 12-13)
- 怎样让CFileDialog能同时选择文件夹与文件
- 【急】WIN下shell做文件图标替换的功能,为啥没生效。。
- 【谁能给一点关于“解压”的一点办法或思路】
- 不能将参数 从“wchar_t *”转换为“const char *”问题
sizeof(filebuf) = 4一些地方需要用 fileSizememset/strcat_s
应该修改成
if (filebuf == NULL)
sizeof(filebuf) = 4?????
怎么回呢
char filebuf[100];
那么,sizeof(filebuf) 是 100;如果你定义
char *filebuf;
...
那么,sizeof(filebuf) 就是 sizeof(char *) ,在 win32 下等于 4
还有之所以错误,是你给filebuf=NULL了。
应该修改成
if (filebuf == NULL)
改了之后没有了,错误很低级啊,
谢谢指点但是执行到strcat_s(filebuf,sizeof(filebuf),temp);这句时,又提示
tcscat_s.inl
Expression:(L"Buffer is too small" &&0)
是怎么回事啊
还是执行到strcat_s(filebuf,filesize,temp);这句时,又提示
tcscat_s.inl
Expression:(L"Buffer is too small" &&0)
memset(filebuf,0,sizeof(filebuf));// 这儿filebuf的长度用sizeof可以得到么?
执行到strcat_s(filebuf,filesize,temp);这句时,又提示
tcscat_s.inl
Expression:(L"Buffer is too small" &&0)
strcat_s()参数filesize应该是strlen(filebuf)+strlen(temp)呢,还是
只要filesize>strlen(temp)就可以了如果我把链接放到循环中,每次strcat_s(filebuf,filesize,temp)就行了吗?中间每次连接的时候'\0'有没有加进去