Skip to content

Up-cast 16-bit integer before shifting by 16 bits

hansmi requested to merge hansmi/usbredir:shift1 into master

The usb_redir_bulk_packet_header.length_high field is of type uint16_t. Shifting it by 16 bits is undefined: "[…] a shift operand value which is […] or is greater than or equal to the total number of bits in this value results in undefined behavior" (explanation from Wikipedia). Also reported by UBSan:

left shift of 65535 by 16 places cannot be represented in type 'int'

With this change the length is always stored in an uint32_t.

Merge request reports