AmendHub

jcs

/

subtext

/

amendments

/

util.h

Amendments on February 15, 2024

util: Add dynamic malloc tracking

The previous malloc note stuff was removed since it required every
xmalloc call to include a string, which was laborious to use and
added a lot of code and memory space having to store all those
strings.
Now when MALLOC_DEBUG is defined, the stack is walked to find the
symbols of each function along the way to xmalloc and pointers to
elements of the symbol table are stored, minimizing the amount of
strings that need to be stored in memory, and providing a way to see
the full stack trace of each allocation with xalloc_print. We can
also check in xfree that the allocation was still in our list to
avoid a double free or a junk free.
jcs made amendment 587 2 months ago

Amendments on February 1, 2024


Amendments on November 14, 2023

util: Add Unix/Mac timestamp conversion macros

jcs made amendment 538 6 months ago

Amendments on March 27, 2023


Amendments on March 2, 2023

util: Turn EXPAND_TO_FIT into grow_to_fit function

This will return false if the xrealloc failed, leaving the original
pointer untouched. With the macro, the pointer would get overwritten
with NULL and not be able to be freed.
jcs made amendment 332 about 1 year ago

Amendments on March 1, 2023

util: Make x* allocation functions no longer fatal on failure

Display a warning, but return NULL
Also remove MALLOC_DEBUG, it is not as helpful as I wanted and just
bloats things having to store all these note strings
jcs made amendment 331 about 1 year ago

Amendments on February 5, 2023

*: Minor fixes found by cppcheck and scan-build

Mostly unused variables
jcs made amendment 300 about 1 year ago

Amendments on November 11, 2022

util: Add a comment explaining EXPAND_TO_FIT

jcs made amendment 278 about 1 year ago

Amendments on September 8, 2022

util: Sync with upstream

jcs made amendment 246 about 1 year ago

Amendments on August 3, 2022

util: Support malloc map compaction by toggling a variable

jcs made amendment 227 about 1 year ago

Amendments on July 31, 2022

util: Add note parameter to xmalloc, xcalloc, and xrealloc

If THINK C supported __func__ this would be much easier, but for now
we have to manually annotate every allocation. This will help find
the source of memory leaks.
jcs made amendment 224 about 1 year ago

Amendments on July 21, 2022

*: Use NewPtr instead of malloc, add malloc and free debugging

Instead of free(ptr), use xfree(&ptr) and after it calls
DisposePtr(ptr), it will update ptr to point at NULL to catch
use-after-frees.
When MALLOC_DEBUG is defined, each allocation is added to a
list, and removed when freed. If it's not in the list at free
time, it's a double-free. Also, instead of pointing pointers at
NULL, point them to a pre-defined block of zeroes and in the
idle loop, periodically check that this block is still zero. This
will also catch use-after-frees in a more reliable (but costly)
way.
jcs made amendment 220 about 1 year ago

Amendments on July 12, 2022

board+folder+mail: Trim trailing whitespace from fields

jcs made amendment 199 about 1 year ago

Amendments on June 30, 2022

sha1: Import from OpenBSD

jcs made amendment 177 about 1 year ago

Amendments on June 22, 2022

util: Add macros for combining char bytes to long/short

This should be easy but doing so from signed chars causes problems,
so casting to unsigned char is needed, but then each needs to be cast
to a long before shifting.
jcs made amendment 161 about 1 year ago

Amendments on June 21, 2022

blanker: Add a simple screen blanker

This will trigger after the configured number of idle seconds, when
there are no active sessions. A mouse click or key press will unblank
right away, otherwise it will unblank automatically after the
configured number of runtime seconds.
This is a more CPU-friendly alternative to a normal screen saver, and
it will only run for a short amount of time to do its job of blanking
the screen to prevent burn-in.
jcs made amendment 159 about 1 year ago

Amendments on June 1, 2022

util: Pre-alloc alert ditl handle, get rid of xmallocarray

calloc does what this did, who knew?
Avoid dynamic allocation in vwarn() so errors about OOM conditions
can succeed
jcs made amendment 112 about 1 year ago

Amendments on May 15, 2022

*: Lots of little cleanup

Remove unused variables and fix some returns
Found by compiling with Clang
jcs made amendment 101 over 2 years ago

Amendments on March 29, 2022


Amendments on February 10, 2022

util: Sync with upstream

jcs made amendment 70 over 2 years ago