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

Commits on Sep 22, 2024

  1. Avoid floating-point division by 0

    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
    bad code committed Sep 22, 2024
    Configuration menu
    Copy the full SHA
    568a37d View commit details
    Browse the repository at this point in the history
  2. Avoid stack-use-after-return

    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
    bad code committed Sep 22, 2024
    Configuration menu
    Copy the full SHA
    cfad636 View commit details
    Browse the repository at this point in the history
  3. Avoid potential uninitialzed variables

    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
    bad code committed Sep 22, 2024
    Configuration menu
    Copy the full SHA
    d4f5919 View commit details
    Browse the repository at this point in the history