summaryrefslogtreecommitdiffstats
path: root/XUtils.c
Commit message (Collapse)AuthorAgeFilesLines
* Use 'fp' name for local 'FILE*' variables.Explorer0912 days1-3/+3
| | | | | | | | | | | It is inappropriate to use the 'fd' name for 'FILE*' variables. POSIX file descriptiors are of type 'int' and are distinguished from ISO C stream pointers (type 'FILE*'). Rename these variables to 'fp', which is a preferred naming in POSIX. (Note that ISO C preferred the 'stream' name for the variables.) No code changes.
* Make memory leak in xRealloc explicitBenny Baumann2024-04-041-2/+9
| | | | | | | | | | | | | | | | | | | | | | | There is an edge case in xRealloc upon failure to realloc memory that manifests when the memory area pointed to by ptr contains pointers. As the structure of ptr is opaque to xRealloc there's no chance for properly releasing the memory for those indirect pointers. The best we could do is release ptr itself, leaving behind an indirect leak of those pointers inside the memory pointed to by ptr. This memory leak is picked up by analyzers like deepcode and GCC 14's -fanalyzer, which causes a lengthy, hard-to-parse diagnostic. Leaving the memory allocated and failing on this code path is properly ignored though (at least with GCC 14). A better solution thus is to keep ptr untouched and instead leak the whole block which avoids this diagnostic on indirectly leaked memory which is free'd by bailing shortly after anyway. This is not a fix, neither was the code we had before. This commit mainly documents an edge case and tries to avoid some hard-to-understand (but unavoidable) leak by making it more blatantly obvious in the used tooling.
* Add cast to please debug buildChristian Göttsche2023-11-041-1/+1
| | | | | | XUtils.c:292:21: error: comparison of integers of different signs: 'ssize_t' (aka 'long') and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare] 292 | assert(res <= count); | ~~~ ^ ~~~~~
* Safe-guard agains kernel issuesBenny Baumann2023-11-031-0/+2
|
* Ensure the buffer is always terminatedBenny Baumann2023-11-031-0/+1
|
* Compare all percentage fields with compareRealNumbers()Explorer092023-08-181-0/+11
| | | | | | | | The SPACESHIP_NUMBER() macro does not work well with floating point values that are possible to be NaNs. Change the compare logic of all percentage fields of Process entries to use compareRealNumbers(). Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Replace isnan() with better comparisons (isgreater(), etc.)Explorer092023-08-181-0/+13
| | | | | | | | | | | | | | | | | | The standard isnan() function is defined to never throw FP exceptions even when the argument is a "signaling" NaN. This makes isnan() more expensive than (x != x) expression unless the compiler flag '-fno-signaling-nans' is given. Introduce functions isNaN(), isNonnegative(), isPositive(), sumPositiveValues() and compareRealNumbers(), and replace isnan() in htop's codebase with the new functions. These functions utilize isgreater() and isgreaterequal() comparisons, which do not throw FP exceptions on "quiet" NaNs, which htop uses extensively. With isnan() removed, there is no need to suppress the warning '-Wno-c11-extensions' in FreeBSD. Remove the code from 'configure.ac'. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Annotate functions with access attributeChristian Göttsche2023-02-181-0/+1
| | | | Supported by GCC since version 10.
* Reformat code baseBenny Baumann2022-10-241-4/+4
| | | | | | | | | | | | | | This includes: - Wrap function implementations - Pointer alignment for function signatures - Pointer alignment for variable declarations - Whitespace after keywords - Whitespace after comma - Whitespace around initializers - Whitespace around operators - Code indentation - Line break for single line statements - Misleading alignment
* Please Clang 15Christian Göttsche2022-08-091-1/+1
| | | | | | | CRT.c:1015:14: error: a function declaration without a prototype is deprecated in all versions of C [-Werror,-Wstrict-prototypes] void CRT_done() { ^ void
* Write full bufferChristian Göttsche2022-06-281-0/+23
| | | | Retry writing after a short write.
* Always abort on overflow in String_catChristian Göttsche2022-05-051-1/+3
| | | | Not only in debug mode.
* Improve String_contains_i to allow for multiple termsDaniel Lange2022-03-251-2/+16
| | | | | | | | | | | This enables: * Multiple filters in the main panel and strace etc. views * Multiple search terms The search terms are separated by "|" and are still fixed strings matched case-insensitive. Added a multi flag at request of BenBE.
* Removed unused String_getToken functionTobias Stoeckmann2022-01-111-29/+0
| | | | | Since String_getToken is not used anymore and currently only supports a 50 char token, simply remove it for now.
* Fix out of boundary writes in XUtilsTobias Stoeckmann2022-01-111-4/+7
| | | | | | | | | | | | | It is possible to exceed the unsigned int data type on 64 bit systems with enough available RAM. Use size_t in all places instead. Proof of Concept: Create a 4 GB line in .htoprc file and run htop $ dd if=/dev/zero bs=1024 count=4194304 | tr '\0' 'a' > ~/.htoprc $ htop Segmentation fault Also avoid overflow of stack based "match" array in String_getToken.
* Update license headers to explicitly say GPLv2+Daniel Lange2021-09-221-1/+1
|
* Add xReallocArrayZero() helperChristian Göttsche2021-09-111-0/+16
| | | | | Add helper function to reallocate an dynamic allocated array including zeroing the newly allocated memory.
* XUtils: move implementation of String_contains_i out of header fileChristian Göttsche2021-08-251-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | The function strcasestr(3) is only available if _GNU_SOURCE is defined. If any file includes <string.h> before declaring _GNU_SOURCE, e.g by including "config.h", compilation fails with the following error: In file included from ColumnsPanel.c:8: In file included from ./ColumnsPanel.h:12: In file included from ./Panel.h:13: In file included from ./CRT.h:16: In file included from ./Settings.h:17: In file included from ./Process.h:15: In file included from ./Object.h:17: ./XUtils.h:42:11: error: implicit declaration of function 'strcasestr' is invalid in C99 [-Werror,-Wimplicit-function-declaration] return strcasestr(s1, s2) != NULL; ^ ./XUtils.h:42:11: note: did you mean 'strcasecmp'? /usr/include/strings.h:116:12: note: 'strcasecmp' declared here extern int strcasecmp (const char *__s1, const char *__s2) ^ Move the implementation to avoid unnecessary includes. Since LTO is quite common and stable performance should not be impacted if used.
* Pointer indication aligned to typenameBenny Baumann2021-07-151-1/+1
|
* Mark several non-modified pointer variables constChristian Göttsche2021-01-111-1/+1
|
* Add wrapper function for free and strdupChristian Göttsche2021-01-111-0/+8
| | | | Reduces code in callers and helps avoiding memory leaks.
* XUtils: add safe strncpy implementationChristian Göttsche2021-01-111-0/+12
| | | | | The standard strncpy fails to null-terminate the destination in case the source is longer than the passed size.
* XUtils: check for multiplication overflow in allocation sizeChristian Göttsche2021-01-021-0/+22
|
* Use size_t as len type for xSnprintfChristian Göttsche2020-12-061-2/+2
| | | | Like the C snprintf function
* IWYU updateChristian Göttsche2020-12-061-0/+1
|
* Add xReadfile wrapper for reading small to medium size filesChristian Göttsche2020-12-021-0/+50
| | | | | | Inspired by proposed Linux syscall Avoid file descriptor leaks like 4af8c63f
* Spacing around operatorsBenny Baumann2020-11-021-4/+4
|
* IWYU updateChristian Göttsche2020-10-201-0/+1
| | | | | | | | | | | - Add Settings forward declaration in Process.h - Add assert.h include in XUitls.c - Add conditional stdbool.h include in Object.h - Drop unneeded stddef.h include in Richstring.c - Drop unneeded unistd.h include in Process.h - Drop unneeded string.h include in linux/Platform.c - Use String_eq to avoid string.h include in Action.c - Improve script to run custom iwyu version
* XUtils string related updatesChristian Göttsche2020-10-191-36/+32
| | | | | | | | | | - allow count out-parameter of String_split() to be NULL - introduce xStrndup() - do not allow NULL pointers passed to String_eq() it is not used in any code - implement String_startsWith(), String_contains_i() and String_eq() as inline header functions - adjust several conversion issues
* Assert allocating non-zero size memoryChristian Göttsche2020-10-191-6/+6
| | | | | | | | Allocating zero size memory results in implementation-defined behavior: man:malloc(3) : If size is 0, then malloc() returns either NULL, or a unique pointer value that can later be successfully passed to free().
* Make all required includes explicitBenny Baumann2020-10-181-2/+1
| | | | Information as seen by IWYU 0.12 + clang 9 on Linux
* Release old memory on errorBenny Baumann2020-10-171-2/+10
| | | | Avoids leaking memory upon realloc failure.
* Combine XAlloc.[ch] into XUtils.[ch]Benny Baumann2020-10-171-1/+30
|
* Rename StringUtils.[ch] to XUtils.[ch]Benny Baumann2020-10-161-0/+179

© 2014-2024 Faster IT GmbH | imprint | privacy policy