string-util: imply NULL termination of strextend() argument list

The trailing NULL in the argument list is now implied (similar to
what we already have in place in strjoin()).
This commit is contained in:
Lennart Poettering
2021-01-06 17:24:46 +01:00
parent 0ec1dc5ba3
commit c2bc710b24
23 changed files with 61 additions and 63 deletions
+2 -2
View File
@@ -1619,7 +1619,7 @@ int cg_slice_to_path(const char *unit, char **ret) {
if (!escaped)
return -ENOMEM;
if (!strextend(&s, escaped, "/", NULL))
if (!strextend(&s, escaped, "/"))
return -ENOMEM;
dash = strchr(dash+1, '-');
@@ -1629,7 +1629,7 @@ int cg_slice_to_path(const char *unit, char **ret) {
if (!e)
return -ENOMEM;
if (!strextend(&s, e, NULL))
if (!strextend(&s, e))
return -ENOMEM;
*ret = TAKE_PTR(s);
+3 -3
View File
@@ -934,7 +934,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
/* Preserve the trailing slash */
if (flags & CHASE_TRAIL_SLASH)
if (!strextend(&done, "/", NULL))
if (!strextend(&done, "/"))
return -ENOMEM;
break;
@@ -1005,7 +1005,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
if (streq_ptr(done, "/"))
*done = '\0';
if (!strextend(&done, first, todo, NULL))
if (!strextend(&done, first, todo))
return -ENOMEM;
exists = false;
@@ -1098,7 +1098,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
if (streq(done, "/"))
*done = '\0';
if (!strextend(&done, first, NULL))
if (!strextend(&done, first))
return -ENOMEM;
}
+10 -10
View File
@@ -791,10 +791,10 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) {
return *ibuf;
}
char *strextend_with_separator(char **x, const char *separator, ...) {
bool need_separator;
char *strextend_with_separator_internal(char **x, const char *separator, ...) {
size_t f, l, l_separator;
char *r, *p;
bool need_separator;
char *nr, *p;
va_list ap;
assert(x);
@@ -818,7 +818,7 @@ char *strextend_with_separator(char **x, const char *separator, ...) {
if (need_separator)
n += l_separator;
if (n > ((size_t) -1) - l) {
if (n >= SIZE_MAX - l) {
va_end(ap);
return NULL;
}
@@ -830,11 +830,12 @@ char *strextend_with_separator(char **x, const char *separator, ...) {
need_separator = !isempty(*x);
r = realloc(*x, l+1);
if (!r)
nr = realloc(*x, l+1);
if (!nr)
return NULL;
p = r + f;
*x = nr;
p = nr + f;
va_start(ap, separator);
for (;;) {
@@ -853,12 +854,11 @@ char *strextend_with_separator(char **x, const char *separator, ...) {
}
va_end(ap);
assert(p == r + l);
assert(p == nr + l);
*p = 0;
*x = r;
return r + l;
return p;
}
char *strrep(const char *s, unsigned n) {
+3 -2
View File
@@ -189,9 +189,10 @@ char *strreplace(const char *text, const char *old_string, const char *new_strin
char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]);
char *strextend_with_separator(char **x, const char *separator, ...) _sentinel_;
char *strextend_with_separator_internal(char **x, const char *separator, ...) _sentinel_;
#define strextend(x, ...) strextend_with_separator(x, NULL, __VA_ARGS__)
#define strextend_with_separator(x, separator, ...) strextend_with_separator_internal(x, separator, __VA_ARGS__, NULL)
#define strextend(x, ...) strextend_with_separator_internal(x, NULL, __VA_ARGS__, NULL)
char *strrep(const char *s, unsigned n);