summaryrefslogtreecommitdiffstats
path: root/XUtils.c
AgeCommit message (Collapse)Author
2022-05-05Always abort on overflow in String_catChristian Göttsche
Not only in debug mode.
2022-03-25Improve String_contains_i to allow for multiple termsDaniel Lange
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.
2022-01-11Removed unused String_getToken functionTobias Stoeckmann
Since String_getToken is not used anymore and currently only supports a 50 char token, simply remove it for now.
2022-01-11Fix out of boundary writes in XUtilsTobias Stoeckmann
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.
2021-09-22Update license headers to explicitly say GPLv2+Daniel Lange
2021-09-11Add xReallocArrayZero() helperChristian Göttsche
Add helper function to reallocate an dynamic allocated array including zeroing the newly allocated memory.
2021-08-25XUtils: move implementation of String_contains_i out of header fileChristian Göttsche
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.
2021-07-15Pointer indication aligned to typenameBenny Baumann
2021-01-11Mark several non-modified pointer variables constChristian Göttsche
2021-01-11Add wrapper function for free and strdupChristian Göttsche
Reduces code in callers and helps avoiding memory leaks.
2021-01-11XUtils: add safe strncpy implementationChristian Göttsche
The standard strncpy fails to null-terminate the destination in case the source is longer than the passed size.
2021-01-02XUtils: check for multiplication overflow in allocation sizeChristian Göttsche
2020-12-06Use size_t as len type for xSnprintfChristian Göttsche
Like the C snprintf function
2020-12-06IWYU updateChristian Göttsche
2020-12-02Add xReadfile wrapper for reading small to medium size filesChristian Göttsche
Inspired by proposed Linux syscall Avoid file descriptor leaks like 4af8c63f
2020-11-02Spacing around operatorsBenny Baumann
2020-10-20IWYU updateChristian Göttsche
- 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
2020-10-19XUtils string related updatesChristian Göttsche
- 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
2020-10-19Assert allocating non-zero size memoryChristian Göttsche
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().
2020-10-18Make all required includes explicitBenny Baumann
Information as seen by IWYU 0.12 + clang 9 on Linux
2020-10-17Release old memory on errorBenny Baumann
Avoids leaking memory upon realloc failure.
2020-10-17Combine XAlloc.[ch] into XUtils.[ch]Benny Baumann
2020-10-16Rename StringUtils.[ch] to XUtils.[ch]Benny Baumann