Menu

A byte being shifted right by 8

2019-11-29
2019-12-02
  • Robert Morin

    Robert Morin - 2019-11-29

    Hi,

    cppcheck didn't detect this problem (neither gcc or clang):

    int f( unsigned char TryThis )
    {
      return TryThis >> 8;
    }
    

    Integer promotion is causing this to be valid but this caused a bug in our system and was not detected until it reached the field.

    Worth to add a small test for this ?

     
  • Daniel Marjamäki

    yes. as you say, it's valid so we can only write some "always 0" warning. that seems helpful. Thanks for your suggestion.

    I created this ticket:
    https://trac.cppcheck.net/ticket/9503

    If you are interested.. feel free to investigate this. Probably it would be good if ValueFlow says that the result is always 0.

     
  • Robert Morin

    Robert Morin - 2019-12-02

    I will give it a try.

    Thanks

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.