Commit Graph

651 Commits

Author SHA1 Message Date
bad code
684fbeb583 Fix devide by 0
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
2025-05-01 11:21:51 +00:00
bad code
7906886e76 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
2025-05-01 11:21:51 +00:00
bad code
9ecc10b66b 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
2025-05-01 11:21:51 +00:00
bad code
1896c3a296 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
2025-05-01 11:21:51 +00:00
Xavi
7fa92c402d Initialize pti struct 2025-05-01 11:14:20 +00:00
Xavi
da9a53f4a9 Fix macos tree-mode + aggregate memory issue 2025-05-01 11:14:20 +00:00
Marie Ramlow
4812ac8280 Fix typo: Mhz -> MHz 2025-05-01 10:53:44 +00:00
aristocratos
666d31b1ab v1.4.1 2025-04-27 15:52:29 +02:00
Steffen Winter
6cab38f097 Fix various typos in code, themes and workflows 2025-04-24 19:39:27 +00:00
bad code
d40cd430b8 Mark destructor noexcept and satisfy rule-of-five
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.
2025-04-24 19:04:02 +00:00
bad code
81cdf9d7c4 Initialize all struct fields
Avoid uninitialized members.
2025-04-24 19:04:02 +00:00
bad code
08706f49d3 Mark member variables private
Hide class internals.
2025-04-24 19:04:02 +00:00
bad code
4c4a161421 Use explicit single parameter constructor
Avoid implicit conversions; these might be unwanted or truncating.
2025-04-24 19:04:02 +00:00
bad code
5ff01e1987 Ensure NUL-termination on truncation
gethostname() might not NUL-terminate the passed buffer on truncation.
2025-04-24 19:04:02 +00:00
bad code
4d67f3211d Avoid repeated bounds check
The bounds check is done explicitly in the line before.
2025-04-24 19:04:02 +00:00
bad code
73e0520fb0 Use O_CLOEXEC
Avoid leaking file descriptor via potential sibling threads.
2025-04-24 19:04:02 +00:00
bad code
c37f68f088 Use member function instead of cast
Avoid C-style cast.
2025-04-24 19:04:02 +00:00
bad code
f72d11fe52 Avoid copy in constructor
Enable compilers to move temporary variables into the constructor.
2025-04-24 19:04:02 +00:00
bad code
889d8efce4 Drop trailing newlines 2025-04-24 19:04:02 +00:00
bad code
48a1fbe3a7 Declare local function static
Clarifies the intended scope of the functions.
2025-04-24 19:04:02 +00:00
bad code
0d14d8672f Drop duplicate include 2025-04-24 19:04:02 +00:00
bad code
c1a31fa167 Simplify ternary expression 2025-04-24 19:04:02 +00:00
bad code
b2b54b5bd7 Use explicit initialization
Avoid uninitialized member variable.
2025-04-24 19:04:02 +00:00
bad code
92ae38d804 Use nullptr for pointer argument
Avoid implicit integer to pointer conversion.
2025-04-24 19:04:02 +00:00
bad code
e0914771cd Add missing override annotations
Help the compiler in finding mismatches.
2025-04-24 19:04:02 +00:00
bad code
bdec3d653f Avoid comma operator
Simply split the expressions.
2025-04-24 19:04:02 +00:00
Stefan
e96f692be5 Fixed typo 2025-04-23 20:40:21 +00:00
bad code
f366b38f85 Avoid copies in ltrim() and ltrim() 2025-04-23 20:15:12 +00:00
bad code
7d3f73b392 Avoid string copies
The sensor data is not modified for the lifetime of the vector and
outlives it.
2025-04-23 20:15:12 +00:00
bad code
de5c8d75ba Drop unused struct members 2025-04-23 20:15:12 +00:00
bad code
34c0532ca7 Reduce variable scope 2025-04-23 20:15:12 +00:00
bad code
c139ded7db Avoid string copy 2025-04-23 20:15:12 +00:00
bad code
124aa592e3 Initialize vector in one step 2025-04-23 20:15:12 +00:00
bad code
ef13690601 Avoid repeated lookup
erase() works fine if the key does not exist.
2025-04-23 20:15:12 +00:00
bad code
b276a60cd3 Avoid repeated lookup
Cache the value once.
2025-04-23 20:15:12 +00:00
bad code
e94a6dc8c0 Avoid repeated lookup
Use find() instead of contains() followed by at().
2025-04-23 20:15:12 +00:00
bad code
4272d32257 Drop unnecessary string construction 2025-04-23 20:15:12 +00:00
bad code
38886e703f Avoid unnecessary copy of vector 2025-04-23 20:15:12 +00:00
bad code
da9d5a47bc Avoid copies in loop iterator 2025-04-23 20:15:12 +00:00
bad code
46d160e91a Reserve known vector size
Allocate the required memory at once.
2025-04-23 20:15:12 +00:00
bad code
124ff839f0 Exit loop only if element found
Currently the loop is only executed at most once, the break probably
should be inside the if block.
2025-04-23 20:15:12 +00:00
Steffen Winter
de0d295f6f Move the config parser in it's own module
Return a struct with options instead of settings globals.
2025-04-23 16:48:02 +00:00
georgev93
25cb3f5a08 Adding a menu option to show bitrates in base 10 separate from the setting to show bytes/bits in base 10 2025-04-23 12:00:57 +00:00
Steffen Winter
b21b1daa84 Drop workarounds for GCC 10
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>
2025-04-19 15:09:58 +00:00
Steffen Winter
4df81010a7 Make arg parser function to snake_case
Signed-off-by: Steffen Winter <steffen.winter@proton.me>
2025-04-19 12:26:30 +00:00
Steffen Winter
161c53b978 Combine help function calls in argument parser
Signed-off-by: Steffen Winter <steffen.winter@proton.me>
2025-04-19 12:26:30 +00:00
Steffen Winter
e6dc808cee Add CLI flag to specify a different config file
Signed-off-by: Steffen Winter <steffen.winter@proton.me>
2025-04-19 12:26:30 +00:00
Steffen Winter
5f9147d55b Use XDG_STATE_HOME to save logs
Closes: #1019

Signed-off-by: Steffen Winter <steffen.winter@proton.me>
2025-04-16 13:32:29 +00:00
Taha YASSINE
e4953efbea Replace brackets with arrows in net box 2025-04-13 15:34:56 +00:00
Taha YASSINE
e68f2a01d1 Replace brackets with arrows in proc box 2025-04-13 15:34:56 +00:00