请问一下
我在跑一项语法检查程式,
但是跳出底下memcpy使用错误,请问是真的有错吗,谢谢
(1)Error: memcpy insufficient space for operation: data: required=2048, available=1
Code:
unsigned char table[2048];
unsigned char *data;
data = kcalloc(2048, sizeof(unsigned char), GFP_KERNEL);
if (data== NULL) {
dev_err(&client->dev, "kcalloc data failed\n");
}
memset(table, 0, sizeof(table));
memcpy(&table[0], data, 2048);
kfree(data);
(2)请问跳出底下memcpy使用错误,请问我的code是真的有错吗,谢谢
Error: Size mismatch in memcpy: g_read_buf[], available:1 , required:4
Code:
unsigned char *g_read_buf,
main()
{
......
g_read_buf = kcalloc(MAX_REPORT_PACKET_SIZE, sizeof(char), GFP_KERNEL);
if (g_read_buf == NULL) {
pr_err("kcalloc g_read_buf failed\n");
}
……
}
int i2c_pda_read(struct i2c_client *client, unsigned int u32_addr, unsigned char *r_data, unsigned short length)
{
struct ts_data *ts = i2c_get_clientdata(client);
struct i2c_msg msg[] = {
{
.addr = I2C_NID,
.flags = I2C_WRITE,
.len = 1,
.buf = &u8_buf,
.scl_rate = 400 * 1000,
},
{
.addr = I2C_NID,
.flags = I2C_READ,
.len = u16_length,
.buf = g_read_buf,
.scl_rate = 400 * 1000,
},
};
u8_mode |= 0x03;
i2c_pda_set_address(ts, u32_addr, u8_mode)
if (i2c_transfer(ts->client->adapter, msg, 2) == 2)
{
memcpy(r_data, g_read_buf, length);
}
return 0;
}