RTEMS | disp_hmsc29xx.c: Coverity flagged negative shift (#5083)
Joel Sherrill (@joel)
gitlab at rtems.org
Fri Aug 2 15:56:16 UTC 2024
Joel Sherrill created an issue: https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5083
Assignee: Joel Sherrill
## Summary
After analysis by myself and @opticron, we realised that this can be fixed by negating the shift_cnt and shifting the other direction. Per git blame, this file was written by Thomas Doerfler and merged in 2008-07-11. This particular area of code is unchanged since then.
CID 1399704
```
245 }
28. Condition shift_cnt < 0, taking true branch.
29. cond_at_most: Checking shift_cnt < 0 implies that shift_cnt may be up to -1 on the true branch.
246 if (shift_cnt < 0) {
CID 1399704: (#1 of 1): Bad bit shift operation (BAD_SHIFT)
30. negative_shift: In expression byte >> shift_cnt, shifting by a negative amount has undefined behavior. The shift amount, shift_cnt, is no more than -1.
247 byte = byte >> shift_cnt;
248 }
249 else if (shift_cnt > 0) {
250 byte = byte >> shift_cnt;
251 }
252 ((unsigned char *)(dst->latin1[glyph_idx]->bitmap))[bcnt] = byte;
253 }
```
## Steps to reproduce
--
View it on GitLab: https://gitlab.rtems.org/rtems/rtos/rtems/-/issues/5083
You're receiving this email because of your account on gitlab.rtems.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/bugs/attachments/20240802/b2f3d24f/attachment-0001.htm>
More information about the bugs
mailing list