[linux-dvb] Problems with ca_zap
Manu Abraham
manu at kromtek.com
Fri Jun 24 20:57:37 CEST 2005
Johannes Stezenbach wrote:
> Manu Abraham wrote:
>>Allan Stirling wrote:
>>> p_program_descriptor->program_number =
>>> ((p_program_descriptor->program_number | buf[pos + 0]) << 8) | buf[pos + 1];
>>>
>>>Doesn't look quite right. Why do we care what the program_number is
>>>before it's been parsed?
>>Hmm, that is required because buf is 8 bits. All what i do is, get buf
>>into program_number and shift program_number to the left by 8.
>>
>>>If I change this to
>>>
>>> p_program_descriptor->program_number =
>>> ( buf[pos + 0] << 8) | buf[pos + 1];
>>>
>>This would be wrong however, since if you left shift an 8 bit buffer by
>>8 all you will get is 0.
>>
>>The problem would be solved, if program_number is initialized to 0 just
>>before reading in from the buffer.
>
> It still would be hard to read. How about:
>
> p_program_descriptor->program_number =
> ((uint16_t) buf[pos] << 8) | buf[pos + 1];
>
buf is uint8_t *buf
so shifting 8 bits left would make buf[pos] = 0 in all eventualities
since uint8_t is 8 bits, and just a cast to uint16_t would help there ?
or am i wrong ?
More information about the linux-dvb
mailing list