Bug 229715

Summary: src/lib/libdevstat/devstat.c:760]: (style) Redundant condition
Product: Base System Reporter: David Binderman <dcb314>
Component: miscAssignee: freebsd-bugs (Nobody) <bugs>
Status: New ---    
Severity: Affects Only Me CC: imp, markj
Priority: ---    
Version: CURRENT   
Hardware: Any   
OS: Any   

Description David Binderman 2018-07-12 09:46:39 UTC
src/lib/libdevstat/devstat.c:760]: (style) Redundant condition: (matches[i].match_fields&DEVSTAT_MATCH_PASS)==0. 'A || (!A && B)' is equivalent to 'A || B'
[src/lib/libdevstat/devstat.c:769]: (style) Redundant condition: (matches[i].match_fields&DEVSTAT_MATCH_PASS)==0. 'A || (!A && B)' is equivalent to 'A || B'

Source code is

                        if ((((matches[i].match_fields & DEVSTAT_MATCH_TYPE)!=0)
                          && ((devices[j].device_type & DEVSTAT_TYPE_MASK) ==
                                (matches[i].device_type & DEVSTAT_TYPE_MASK))
                          &&(((matches[i].match_fields & DEVSTAT_MATCH_PASS)!=0)
                           || (((matches[i].match_fields &
                                DEVSTAT_MATCH_PASS) == 0)
                            && ((devices[j].device_type &
                                DEVSTAT_TYPE_PASS) == 0)))
                          && (--num_match_categories == 0))
                         || (((matches[i].match_fields & DEVSTAT_MATCH_IF) != 0)
                          && ((devices[j].device_type & DEVSTAT_TYPE_IF_MASK) ==
                                (matches[i].device_type & DEVSTAT_TYPE_IF_MASK))
                          &&(((matches[i].match_fields & DEVSTAT_MATCH_PASS)!=0)
                           || (((matches[i].match_fields &
                                DEVSTAT_MATCH_PASS) == 0)
                            && ((devices[j].device_type &
                                DEVSTAT_TYPE_PASS) == 0)))
                          && (--num_match_categories == 0))
                         || (((matches[i].match_fields & DEVSTAT_MATCH_PASS)!=0)
                          && ((devices[j].device_type & DEVSTAT_TYPE_PASS) != 0)
                          && (--num_match_categories == 0))) {

20 or so lines of if statement could IMHO do with some simplifying.
Comment 1 Warner Losh freebsd_committer freebsd_triage 2018-07-12 18:02:52 UTC
This is a fair assessment, especially given the side effects of this crazy if statement.