I have the following piece of code:
long int compute_data_length(unsigned char* buf, int data_offset) {
long int len;
if(!buf)
return -1;
switch(data_offset) {
case 2: {
len = (buf[2] << 8) | buf[3];
}
break;
case 8: {
len = (buf[2] << 56) |
(buf[3] << 48) |
(buf[4] << 40) |
(buf[5] << 32) |
(buf[6] << 24) |
(buf[7] << 16) |
(buf[8] << 8) |
(buf[9] );
}
break;
default: len = -1; break;
}
return len;
}
When I compile, I get the following warning:
math_fun.c:240:21: warning: left shift count >= width of type [enabled by default] len = (buf[2] << 56) | ^ math_fun.c:241:27: warning: left shift count >= width of type [enabled by default] (buf[3] << 48) | ^ math_fun.c:242:27: warning: left shift count >= width of type [enabled by default] (buf[4] << 40) | ^ math_fun.c:243:27: warning: left shift count >= width of type [enabled by default] (buf[5] << 32) |
How do I fix the warning?