Răsfoiți Sursa

Fixed minor bug in xs_regex_split_n().

grunfink 1 lună în urmă
părinte
comite
a4bbb848f2
3 a modificat fișierele cu 14 adăugiri și 6 ștergeri
  1. 10 3
      xs.h
  2. 3 2
      xs_regex.h
  3. 1 1
      xs_version.h

+ 10 - 3
xs.h

@@ -141,6 +141,7 @@ const char *xs_number_str(const xs_number *v);
 
 xs_data *xs_data_new(const void *data, int size);
 int xs_data_size(const xs_data *value);
+const void *xs_data_ptr(const xs_data *value);
 void xs_data_get(void *data, const xs_data *value);
 
 void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size);
@@ -965,10 +966,9 @@ int xs_list_in(const xs_list *list, const xs_val *val)
 
     int n = 0;
     const xs_val *v;
-    int sz = xs_size(val);
 
     xs_list_foreach(list, v) {
-        if (sz == xs_size(v) && memcmp(val, v, sz) == 0)
+        if (xs_cmp(val, v) == 0)
             return n;
 
         n++;
@@ -1524,10 +1524,17 @@ int xs_data_size(const xs_data *value)
 }
 
 
+const void *xs_data_ptr(const xs_data *value)
+/* return an internal pointer to the stored data */
+{
+    return &value[1 + _XS_TYPE_SIZE];
+}
+
+
 void xs_data_get(void *data, const xs_data *value)
 /* copies the raw data stored inside value into data */
 {
-    memcpy(data, &value[1 + _XS_TYPE_SIZE], xs_data_size(value));
+    memcpy(data, xs_data_ptr(value), xs_data_size(value));
 }
 
 

+ 3 - 2
xs_regex.h

@@ -35,12 +35,12 @@ xs_list *xs_regex_split_n(const char *str, const char *rx, int count)
     regmatch_t rm;
     int offset = 0;
     xs_list *list = xs_list_new();
-    const char *p;
+    const char *p = str;
 
     if (regcomp(&re, rx, REG_EXTENDED))
         return list;
 
-    while (count > 0 && !regexec(&re, (p = str + offset), 1, &rm, offset > 0 ? REG_NOTBOL : 0)) {
+    while (count > 0 && !regexec(&re, p, 1, &rm, offset > 0 ? REG_NOTBOL : 0)) {
         /* add first the leading part of the string */
         xs *s1 = xs_str_new_sz(p, rm.rm_so);
 
@@ -55,6 +55,7 @@ xs_list *xs_regex_split_n(const char *str, const char *rx, int count)
         offset += rm.rm_eo;
 
         count--;
+        p = str + offset;
     }
 
     /* add the rest of the string */

+ 1 - 1
xs_version.h

@@ -1 +1 @@
-/* 8c7b288a0e0eac3a61f7c465633499b2fd44ca61 2026-04-05T10:14:27+02:00 */
+/* 2e209276f3f598dbee88350a33291198ab792eb2 2026-06-03T19:54:14+02:00 */