ucx/printf.c

changeset 888
af685cc9d623
parent 852
83fdf679df99
--- a/ucx/printf.c	Sun Aug 31 14:39:13 2025 +0200
+++ b/ucx/printf.c	Sat Nov 08 23:06:11 2025 +0100
@@ -68,7 +68,7 @@
         return (int) wfc(buf, 1, ret, stream);
     } else {
         int len = ret + 1;
-        char *newbuf = malloc(len);
+        char *newbuf = cxMallocDefault(len);
         if (!newbuf) { // LCOV_EXCL_START
             va_end(ap2);
             return -1;
@@ -79,7 +79,7 @@
         if (ret > 0) {
             ret = (int) wfc(newbuf, 1, ret, stream);
         }
-        free(newbuf);
+        cxFreeDefault(newbuf);
     }
     return ret;
 }
@@ -121,7 +121,7 @@
         if (s.ptr) {
             ret = vsnprintf(s.ptr, len, fmt, ap2);
             if (ret < 0) {
-                free(s.ptr);
+                cxFree(a, s.ptr);
                 s.ptr = NULL;
             } else {
                 s.length = (size_t) ret;
@@ -132,7 +132,13 @@
     return s;
 }
 
-int cx_sprintf_a(CxAllocator *alloc, char **str, size_t *len, const char *fmt, ... ) {
+int cx_sprintf_a(
+        const CxAllocator *alloc,
+        char **str,
+        size_t *len,
+        const char *fmt,
+        ...
+) {
     va_list ap;
     va_start(ap, fmt);
     int ret = cx_vsprintf_a(alloc, str, len, fmt, ap);
@@ -140,7 +146,13 @@
     return ret;
 }
 
-int cx_vsprintf_a(CxAllocator *alloc, char **str, size_t *len, const char *fmt, va_list ap) {
+int cx_vsprintf_a(
+        const CxAllocator *alloc,
+        char **str,
+        size_t *len,
+        const char *fmt,
+        va_list ap
+) {
     va_list ap2;
     va_copy(ap2, ap);
     int ret = vsnprintf(*str, *len, fmt, ap);
@@ -162,7 +174,14 @@
     return ret;
 }
 
-int cx_sprintf_sa(CxAllocator *alloc, char *buf, size_t *len, char **str, const char *fmt, ... ) {
+int cx_sprintf_sa(
+        const CxAllocator *alloc,
+        char *buf,
+        size_t *len,
+        char **str,
+        const char *fmt,
+        ...
+) {
     va_list ap;
     va_start(ap, fmt);
     int ret = cx_vsprintf_sa(alloc, buf, len, str, fmt, ap);
@@ -170,7 +189,14 @@
     return ret;
 }
 
-int cx_vsprintf_sa(CxAllocator *alloc, char *buf, size_t *len, char **str, const char *fmt, va_list ap) {
+int cx_vsprintf_sa(
+        const CxAllocator *alloc,
+        char *buf,
+        size_t *len,
+        char **str,
+        const char *fmt,
+        va_list ap
+) {
     va_list ap2;
     va_copy(ap2, ap);
     int ret = vsnprintf(buf, *len, fmt, ap);

mercurial