我是 c 编程新手,我正在编写一个简单的客户端服务器应用程序。我收到这条消息:
Source and destination overlap in memcpy(0x41f0beb, 0x41f0258, 69141077)
==9522== at 0x402D9A9: memcpy (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==9522== by 0x8049C13: message_to_buffer (message.c:92)
下面是具体代码:
case CT_ENTRY://100
{
int c=(2+2+4+strlen(msg->content.entry->key)-1+4+4+strlen(msg->content.entry->value->data));
char *offset=malloc(c);
*msg_buf=offset;
memcpy(offset,&opcode,2);
offset+=2;
memcpy(offset,&ctype,2 );
offset+=2;
int ks=strlen(msg->content.entry->key);
int ksc=host_to_net(ks);
memcpy(offset,&ksc,4);
offset+=4;
memcpy(offset, msg->content.entry->key, ks);
offset+=ks;
int l=host_to_net(get_time());
memcpy(offset,&l,4);
offset+=4;
int ds=host_to_net(msg->content.entry->value->datasize);
memcpy(offset,&ds,4);
offset+=4;
// this line here!
memcpy(offset,msg->content.entry->value->data, msg->content.value->datasize);
return c;
break;
违规行是
memcpy(offset,msg->content.entry->value->data, msg->content.value->datasize);
谁能解释为什么会这样?谢谢