I have a struct like:
struct holder {
int prio;
long id;
char * data;
}
But for some reason, I will be using malloced space for just id and data (not the pointer, the actual data).
Now I'm copying the data from holder to the other space like this:
struct holder * my_elem = next_data();
void * buf_k = kmalloc(sizeof(long) + maxlen * sizeof(char), GFP_KERNEL);
memcpy(buf_k, &(my_elem->id), sizeof(long));
memcpy((void *)((char *)buf_k + sizeof(long) * sizeof(char)), my_elem->data, sizeof(char) * str_len(my_elem->data));
However, the code fragment (void *)((char *)buf_k + sizeof(long) * sizeof(char))
is seemed weird to my collugues. Especially the part sizeof(long) * sizeof(char)
. Isn't it correct, or is it just a weird way of doing the right thing?