Fix 'operands of different size in bitwise operation' klockwork issue. (#5914)

* Fix 'operands of different size in bitwise operation' klockwork issue.

* Changed 'byte_idx' type to size_t.
This commit is contained in:
Jozef Daniecki 2021-06-02 07:50:10 +02:00 committed by GitHub
parent 9970f5b248
commit 143fc069a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,8 +19,8 @@ namespace ngraph
{ {
inline void set_u1(uint8_t* buf, size_t idx, uint8_t val) inline void set_u1(uint8_t* buf, size_t idx, uint8_t val)
{ {
const int byte_idx = idx / 8; const size_t byte_idx = idx / 8;
const int bit_idx = 7 - (idx % 8); const uint8_t bit_idx = 7 - (idx % 8);
if (val) if (val)
{ {
buf[byte_idx] |= (1 << bit_idx); buf[byte_idx] |= (1 << bit_idx);
@ -33,38 +33,38 @@ namespace ngraph
inline uint8_t get_u1(const uint8_t* buf, size_t idx) inline uint8_t get_u1(const uint8_t* buf, size_t idx)
{ {
const int byte_idx = idx / 8; const size_t byte_idx = idx / 8;
const int bit_idx = 7 - (idx % 8); const uint8_t bit_idx = 7 - (idx % 8);
return (buf[byte_idx] & (1 << bit_idx)) ? 1 : 0; return (buf[byte_idx] & (1 << bit_idx)) ? 1 : 0;
} }
inline void set_u4(uint8_t* buf, size_t idx, uint8_t val) inline void set_u4(uint8_t* buf, size_t idx, uint8_t val)
{ {
const int byte_idx = idx / 2; const size_t byte_idx = idx / 2;
const int bit_shift = 4 * (++idx % 2); const uint8_t bit_shift = 4 * (++idx % 2);
buf[byte_idx] &= ~(0xF << bit_shift); // half byte zeroed buf[byte_idx] &= ~(0xF << bit_shift); // half byte zeroed
buf[byte_idx] |= (val << bit_shift); // set 1's buf[byte_idx] |= (val << bit_shift); // set 1's
} }
inline uint8_t get_u4(const uint8_t* buf, size_t idx) inline uint8_t get_u4(const uint8_t* buf, size_t idx)
{ {
const int byte_idx = idx / 2; const size_t byte_idx = idx / 2;
const int bit_shift = 4 * (++idx % 2); const uint8_t bit_shift = 4 * (++idx % 2);
return (buf[byte_idx] >> bit_shift) & 0xF; return (buf[byte_idx] >> bit_shift) & 0xF;
} }
inline void set_i4(uint8_t* buf, size_t idx, int8_t val) inline void set_i4(uint8_t* buf, size_t idx, int8_t val)
{ {
const int byte_idx = idx / 2; const size_t byte_idx = idx / 2;
const int bit_shift = 4 * (++idx % 2); const uint8_t bit_shift = 4 * (++idx % 2);
buf[byte_idx] &= ~(0xF << bit_shift); // half byte zeroed buf[byte_idx] &= ~(0xF << bit_shift); // half byte zeroed
buf[byte_idx] |= (val << bit_shift); // set 1's buf[byte_idx] |= (val << bit_shift); // set 1's
} }
inline int8_t get_i4(const uint8_t* buf, size_t idx) inline int8_t get_i4(const uint8_t* buf, size_t idx)
{ {
const int byte_idx = idx / 2; const size_t byte_idx = idx / 2;
const int bit_shift = 4 * (++idx % 2); const uint8_t bit_shift = 4 * (++idx % 2);
uint8_t val = (buf[byte_idx] >> bit_shift) & 0xF; uint8_t val = (buf[byte_idx] >> bit_shift) & 0xF;
if (val & 0x08) if (val & 0x08)
{ // negative number { // negative number