Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please clang with sanitizers #929

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

bad-co-de
Copy link

Resolve two issues while running with sanitizers and two possible uninitialized variables.

bad code added 3 commits September 22, 2024 15:23
Reported by UBSAN:

    src/linux/btop_collect.cpp:1933:57: runtime error: division by zero
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/linux/btop_collect.cpp:1933:57
    src/linux/btop_collect.cpp:2038:93: runtime error: division by zero
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/linux/btop_collect.cpp:2038:93
The variable free_priv is a constant bool; pass by value.
Reported by Address Sanitizer:

    SUMMARY: AddressSanitizer: stack-use-after-return src/linux/btop_collect.cpp:1931:17 in Mem::collect(bool)::$_0::operator()() const
Reported-by clang:

    src/linux/btop_collect.cpp:489:10: error: variable 'high' may be uninitialized when used here [-Werror,-Wconditional-uninitialized]
      489 |                                         if (high < 1) high = 80;
          |                                             ^~~~
    src/linux/btop_collect.cpp:482:18: note: initialize the variable 'high' to silence this warning
      482 |                                         int64_t high, crit;
          |                                                     ^
          |                                                      = 0
    src/linux/btop_collect.cpp:490:10: error: variable 'crit' may be uninitialized when used here [-Werror,-Wconditional-uninitialized]
      490 |                                         if (crit < 1) crit = 95;
          |                                             ^~~~
    src/linux/btop_collect.cpp:482:24: note: initialize the variable 'crit' to silence this warning
      482 |                                         int64_t high, crit;
          |                                                           ^
          |                                                            = 0
    src/linux/btop_collect.cpp:1648:29: error: variable 'totalMem' may be uninitialized when used here [-Werror,-Wconditional-uninitialized]
     1648 |                 if (not meminfo.good() or totalMem == 0)
          |                                           ^~~~~~~~
    src/linux/btop_collect.cpp:1642:19: note: initialize the variable 'totalMem' to silence this warning
     1642 |                 int64_t totalMem;
          |                                 ^
          |                                  = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant