更新:char、signed char 还是 unsigned 的问题最终在这里没有意义。在这种情况下使用 memcpy 更合适,因为它不分青红皂白地作用于字节。
不可能是一个更简单的操作,但我似乎错过了一个关键步骤。在下面的代码中,我试图填充bufferdata
编译buffer
器警告我签名差异的内容。
unsigned char buffer[4096] = {0};
char *bufferdata;
bufferdata = (char*)malloc(4096 * sizeof(bufferdata));
if (! bufferdata)
return false;
while( ... )
{
// nextBlock( voidp _buffer, unsigned _length );
read=nextBlock( buffer, 4096);
if( read > 0 )
{
bufferdata = strncat(bufferdata, buffer, read); // (help)
// leads to: pointer targets in passing argument 2 of strncat differ in signedness.
if(read == 4096) {
// let's go for another chunk
bufferdata = (char*)realloc(bufferdata, ( strlen(bufferdata) + (4096 * sizeof(bufferdata)) ) );
if (! bufferdata) {
printf("failed to realloc\n");
return false;
}
}
}
else if( read<0 )
{
printf("error.\n");
break;
}
else {
printf("done.\n");
break;
}
}