src/string.c

changeset 1125
6090c455b8df
parent 1074
e8e2813cdda6
--- a/src/string.c	Sun Jan 12 13:25:50 2025 +0100
+++ b/src/string.c	Tue Jan 14 21:40:29 2025 +0100
@@ -295,7 +295,7 @@
 
     // check needle length and use appropriate prefix table
     // if the pattern exceeds static prefix table, allocate on the heap
-    bool useheap = needle.length >= CX_STRSTR_SBO_SIZE;
+    const bool useheap = needle.length >= CX_STRSTR_SBO_SIZE;
     register size_t *ptable = useheap ? calloc(needle.length + 1,
                                                sizeof(size_t)) : s_prefix_table;
 
@@ -334,7 +334,7 @@
     }
 
     // if prefix table was allocated on the heap, free it
-    if (ptable != s_prefix_table) {
+    if (useheap) {
         free(ptable);
     }
 

mercurial