bloguetronica / cp2130-qt

A C++ class that uses libusb to interface with CP2130 devices. It can be used to configure the OTP ROM of such devices, as well as to control them. The class was made for Qt. If you wish to use a derived non-Qt version, please refer to https://github.com/bloguetronica/cp2130.
0 stars 0 forks source link

Unchecked promotions to int inside "cp2130.cpp", lines 417 and 614 #26

Closed samuelfmlourenco closed 2 years ago

samuelfmlourenco commented 2 years ago

There are two instances of unchecked promotions to int, in lines 417 and 614. For example, in line 435 we have:

evtcntr.mode = 0x07 & controlBufferIn[0];

However, this is not good practice, because "evtcntr.mode" is a quint8 and the bitwise AND operator (&) promotes the operands to int. The result should be cast to quint8.

evtcntr.mode = static_cast<quint8>(0x07 & controlBufferIn[0]);

Similarly, line 614 should be rewritten, as follows:

mode.cfrq = static_cast<quint8>(0x07 & controlBufferIn[channel]);

samuelfmlourenco commented 2 years ago

Fix implemented in version 2.2.2.