jcs
/amend
/amendments
/191
util: Fix xrealloc when size shrinks
jcs made amendment 191 18 days ago
--- util.c Fri Oct 2 17:48:06 2026
+++ util.c Sun Oct 4 00:01:32 2026
@@ -370,10 +370,12 @@ void *
xrealloc(void *src, size_t size)
{
void *ptr, *tsrc;
+ size_t old_size;
ptr = xmalloc(size, 0);
if (ptr != NULL && src != NULL) {
- memcpy(ptr, src, size);
+ old_size = GetPtrSize(src);
+ memcpy(ptr, src, MIN(old_size, size));
tsrc = src;
xfree(&tsrc);
}