ucx/string.c

branch
dav-2
changeset 891
4d58cbcc9efa
parent 889
42cdbf9bbd49
--- a/ucx/string.c	Sun Dec 07 20:16:59 2025 +0100
+++ b/ucx/string.c	Fri Dec 19 17:53:18 2025 +0100
@@ -25,7 +25,8 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  * POSSIBILITY OF SUCH DAMAGE.
  */
-#ifdef MEMRCHR_NEED_GNU
+
+#ifdef WITH_MEMRCHR
 #define _GNU_SOURCE
 #endif
 
@@ -46,28 +47,6 @@
 #define cx_strcasecmp_impl strncasecmp
 #endif
 
-cxmutstr cx_mutstr(char *cstring) {
-    return (cxmutstr) {cstring, cstring == NULL ? 0 : strlen(cstring)};
-}
-
-cxmutstr cx_mutstrn(
-        char *cstring,
-        size_t length
-) {
-    return (cxmutstr) {cstring, length};
-}
-
-cxstring cx_str(const char *cstring) {
-    return (cxstring) {cstring, cstring == NULL ? 0 : strlen(cstring)};
-}
-
-cxstring cx_strn(
-        const char *cstring,
-        size_t length
-) {
-    return (cxstring) {cstring, length};
-}
-
 void cx_strfree(cxmutstr *str) {
     if (str == NULL) return;
     cxFreeDefault(str->ptr);
@@ -91,7 +70,7 @@
         cxstring src
 ) {
     if (cxReallocate(alloc, &dest->ptr, src.length + 1)) {
-        return 1;
+        return 1; // LCOV_EXCL_LINE
     }
 
     memcpy(dest->ptr, src.ptr, src.length);
@@ -137,7 +116,7 @@
     size_t slen = str.length;
     for (size_t i = 0; i < count; i++) {
         cxstring s = va_arg(ap, cxstring);
-        if (slen > SIZE_MAX - str.length) overflow = true;
+        if (slen > SIZE_MAX - s.length) overflow = true;
         slen += s.length;
     }
     va_end(ap);
@@ -156,10 +135,10 @@
     } else {
         newstr = cxRealloc(alloc, str.ptr, slen + 1);
     }
-    if (newstr == NULL) {
+    if (newstr == NULL) { // LCOV_EXCL_START
         va_end(ap2);
         return (cxmutstr) {NULL, 0};
-    }
+    } // LCOV_EXCL_STOP
     str.ptr = newstr;
 
     // concatenate strings
@@ -521,10 +500,12 @@
             cxMalloc(allocator, string.length + 1),
             string.length
     };
+    // LCOV_EXCL_START
     if (result.ptr == NULL) {
         result.length = 0;
         return result;
     }
+    // LCOV_EXCL_STOP
     memcpy(result.ptr, string.ptr, string.length);
     result.ptr[string.length] = '\0';
     return result;

mercurial