Bug 229715 - src/lib/libdevstat/devstat.c:760]: (style) Redundant condition
Summary: src/lib/libdevstat/devstat.c:760]: (style) Redundant condition
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-07-12 09:46 UTC by David Binderman
Modified: 2024-11-27 07:07 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.