summaryrefslogtreecommitdiff
path: root/xs.h
diff options
context:
space:
mode:
authordefault <nobody@localhost>2023-09-23 18:46:24 +0200
committerdefault <nobody@localhost>2023-09-23 18:46:24 +0200
commit291331c74557786cf5ef5b62a647048131f1394c (patch)
tree08e4f0cd8876181ed5a071842ab535b0f3243c20 /xs.h
parentac8790c3cd1dae815e276de000a5b31a437be7e8 (diff)
Backport from xs.
Diffstat (limited to 'xs.h')
-rw-r--r--xs.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/xs.h b/xs.h
index 40dd706..1fe210e 100644
--- a/xs.h
+++ b/xs.h
@@ -849,17 +849,18 @@ xs_str *xs_join(const xs_list *list, const char *sep)
int sz;
/* add the separator */
- if (c != 0) {
+ if (c != 0 && ssz) {
s = xs_realloc(s, offset + ssz);
memcpy(s + offset, sep, ssz);
offset += ssz;
}
/* add the element */
- sz = strlen(v);
- s = xs_realloc(s, offset + sz);
- memcpy(s + offset, v, sz);
- offset += sz;
+ if ((sz = strlen(v)) > 0) {
+ s = xs_realloc(s, offset + sz);
+ memcpy(s + offset, v, sz);
+ offset += sz;
+ }
c++;
}