我收到此警告
warning C4309: 'initializing' : truncation of constant value
当我尝试执行我的 dll 时,它只发送 4 个字节而不是 10 个字节。
有什么问题?
这是我的代码:
int WINAPI MySend(SOCKET s, const char* buf, int len, int flags)
{
cout << "[SEND:" << len << "] ";
for ( int i = 0; i < len; i++ ) {
printf( "%02x ", static_cast<unsigned char>( buf[i] ) );
}
printf("\n");
//causing the warning:
char storagepkt[] = {0x0A, 0x00, 0x01, 0x40, 0x79, 0xEA, 0x60, 0x1D, 0x6B, 0x3E};
buf = storagepkt;
len = sizeof(storagepkt);
return pSend(s, buf, len, flags);
}
更新
int (WINAPI *pSend)(SOCKET s, const char* buf, int len, int flags) = send;
int WINAPI MySend(SOCKET s, const char* buf, int len, int flags);
更新
正如建议的那样,我尝试了 memcpy:
memcpy((char*) buf, storagepkt, sizeof(storagepkt));
更新
unsigned char storagepkt[] = {0x0A, 0x00, 0x01, 0x40, 0x79, 0xEA, 0x60, 0x1D, 0x6B, 0x3E};
修复。