On 09/04/2026 03:58, Collin Funk wrote:
Pádraig Brady <[email protected]> writes:
On 08/04/2026 15:11, Pádraig Brady wrote:
* src/cat.c (main): Only resize the allocated buffer when needed,
which avoids per file heap manipulation and mmap/munmap syscalls.
---
+static char *
+ensure_buf_size (char *buf, idx_t *buf_alloc, idx_t alignment, idx_t size)
+{
+ if (*buf_alloc < size)
+ {
+ alignfree (buf);
+ buf = xalignalloc (alignment, size);
+ *buf_alloc = size;
+ }
+
+ return buf;
+}
+
BTW I was tempted to avoid the valgrind / ASAN complaints
re using align_alloc() with non page aligned size, with the following,
but refrained since this was already considered as OK
as per the references in lib/alignalloc.h.
Hmm, maybe it's worth putting something like that in #ifdef lint.
I didn't see errors caused by the first patch when using:
$ ./configure CFLAGS='-fsanitize=address,undefined' \
CXXFLAGS='-fsanitize=address,undefined'
Am I missing some option? I was using gcc, if that matters.
I haven't really used valgrind in coreutils, since until recently the
steps in README-valgrind were outdated.
Sorry, my comments were confusing.
aligned_alloc is actually avoided under sanitizer builds.
Also since valgrind supports suppressions we shouldn't further
complicate the code, so I son't add the proposed size adjustment
for dev builds.
cheers,
Padraig