src/linux/btop_collect.cpp:950:106: runtime error: division by zero
#0 0x61b286115a41 in Cpu::collect(bool) src/linux/btop_collect.cpp:950:106
#1 0x61b285e55cb7 in Runner::_runner(void*) src/btop.cpp:533:18
#2 0x61b285e085ca in asan_thread_start(void*) asan_interceptors.cpp.o
#3 0x7629b7719b7a in start_thread nptl/pthread_create.c:448:8
#4 0x7629b77977b7 in __GI___clone3 misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/linux/btop_collect.cpp:950:106
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
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 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
Follow the RAII paradigm and define all 5 special class function if any
of them has a non-default implementation. Avoids duplicate destruction
or other unwanted effects.
GCC 10 and even 11 don't receive updates anymore.
Using Debian stable as the baseline (as done previously), most major
distributions have a recent enought toolchain with GCC 11 or later. The
same applies for LLVM.
Signed-off-by: Steffen Winter <steffen.winter@proton.me>