10002 librcm: bitwise comparison always evaluates to false

Review Request #1294 — Created Nov. 22, 2018 and submitted

tsoome
illumos-gate
10002
cc3f319...
general
../librcm.c:139:46: error: bitwise comparison always evaluates to false [-Werror=tautological-compare]
      ((flag & RCM_DR_OPERATION|RCM_MOD_INFO) == 0)) {
                                              ^~
cc1: all warnings being treated as errors


  • 0
  • 0
  • 2
  • 0
  • 2
Description From Last Updated
alp
  1. Ship It!
  2. 
      
seeemef@mac.com
  1. 
      
  2. usr/src/lib/librcm/librcm.c (Diff revision 1)
     
     

    Maybe excess parentheses resulted in unclarity and the bug to begin with? I wonder if instead of adding a couple more parentheses, trimming down to one outer pair for the if and one pair for the OR-ed bits would be clearer.

  3. 
      
domag02
  1. 
      
  2. usr/src/lib/librcm/librcm.c (Diff revision 1)
     
     

    Missing blanks around |, should be:

    ((flag & (RCM_DR_OPERATION | RCM_MOD_INFO)) == 0)) {
    

    From C Style and Coding Standards for SunOS, page 17:

    All binary operators except . and –> should be separated from their operands by blanks. In other words, blanks should appear around assignment, arithmetic, relational, and logical operators. Blanks should never separate unary operators such as unary minus, address (‘&’), indirection (‘*’), increment (‘++’), and decrement (‘--’) from their operands. Note that this includes the unary * that is a part of pointer declarations.

  3. 
      
tsoome
domag02
  1. 
      
  2. usr/src/lib/librcm/librcm.c (Diff revision 2)
     
     

    Wrong evaluation order:
    1. rsrcname == NULL
    2. (RCM_DR_OPERATION | RCM_MOD_INFO) == 0 evalutes to 0
    3. flag & 0
    4. (rsrcname == NULL) && (flag & 0)

    1. "s/evalutes/evaluates/"
  3. 
      
tsoome
domag02
  1. Another solution (to remove == 0):

        if (rsrcname == NULL && flag & ~(RCM_DR_OPERATION | RCM_MOD_INFO)) {
    
    1. except that too would be against cstyle.

  2. 
      
seeemef@mac.com
  1. I apologize for the mistake in my suggestion!

    1. NP at all, I was on automatic go myself too:)

  2. 
      
alp
  1. Ship It!
  2. 
      
tsoome
Review request changed

Status: Closed (submitted)

Loading...