diff options
| author | 2023-09-23 18:46:24 +0200 | |
|---|---|---|
| committer | 2023-09-23 18:46:24 +0200 | |
| commit | 291331c74557786cf5ef5b62a647048131f1394c (patch) | |
| tree | 08e4f0cd8876181ed5a071842ab535b0f3243c20 /xs.h | |
| parent | If a metadata starts with https:, convert it to a link. (diff) | |
| download | penes-snac2-291331c74557786cf5ef5b62a647048131f1394c.tar.gz penes-snac2-291331c74557786cf5ef5b62a647048131f1394c.tar.xz penes-snac2-291331c74557786cf5ef5b62a647048131f1394c.zip | |
Backport from xs.
Diffstat (limited to 'xs.h')
| -rw-r--r-- | xs.h | 11 |
1 files changed, 6 insertions, 5 deletions
| @@ -849,17 +849,18 @@ xs_str *xs_join(const xs_list *list, const char *sep) | |||
| 849 | int sz; | 849 | int sz; |
| 850 | 850 | ||
| 851 | /* add the separator */ | 851 | /* add the separator */ |
| 852 | if (c != 0) { | 852 | if (c != 0 && ssz) { |
| 853 | s = xs_realloc(s, offset + ssz); | 853 | s = xs_realloc(s, offset + ssz); |
| 854 | memcpy(s + offset, sep, ssz); | 854 | memcpy(s + offset, sep, ssz); |
| 855 | offset += ssz; | 855 | offset += ssz; |
| 856 | } | 856 | } |
| 857 | 857 | ||
| 858 | /* add the element */ | 858 | /* add the element */ |
| 859 | sz = strlen(v); | 859 | if ((sz = strlen(v)) > 0) { |
| 860 | s = xs_realloc(s, offset + sz); | 860 | s = xs_realloc(s, offset + sz); |
| 861 | memcpy(s + offset, v, sz); | 861 | memcpy(s + offset, v, sz); |
| 862 | offset += sz; | 862 | offset += sz; |
| 863 | } | ||
| 863 | 864 | ||
| 864 | c++; | 865 | c++; |
| 865 | } | 866 | } |