X Tutup
Skip to content

Commit c2bc710

Browse files
committed
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()).
1 parent 0ec1dc5 commit c2bc710

File tree

23 files changed

+61
-63
lines changed

23 files changed

+61
-63
lines changed

src/basic/cgroup-util.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ int cg_slice_to_path(const char *unit, char **ret) {
16191619
if (!escaped)
16201620
return -ENOMEM;
16211621

1622-
if (!strextend(&s, escaped, "/", NULL))
1622+
if (!strextend(&s, escaped, "/"))
16231623
return -ENOMEM;
16241624

16251625
dash = strchr(dash+1, '-');
@@ -1629,7 +1629,7 @@ int cg_slice_to_path(const char *unit, char **ret) {
16291629
if (!e)
16301630
return -ENOMEM;
16311631

1632-
if (!strextend(&s, e, NULL))
1632+
if (!strextend(&s, e))
16331633
return -ENOMEM;
16341634

16351635
*ret = TAKE_PTR(s);

src/basic/fs-util.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
934934
/* Preserve the trailing slash */
935935

936936
if (flags & CHASE_TRAIL_SLASH)
937-
if (!strextend(&done, "/", NULL))
937+
if (!strextend(&done, "/"))
938938
return -ENOMEM;
939939

940940
break;
@@ -1005,7 +1005,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
10051005
if (streq_ptr(done, "/"))
10061006
*done = '\0';
10071007

1008-
if (!strextend(&done, first, todo, NULL))
1008+
if (!strextend(&done, first, todo))
10091009
return -ENOMEM;
10101010

10111011
exists = false;
@@ -1098,7 +1098,7 @@ int chase_symlinks(const char *path, const char *original_root, unsigned flags,
10981098
if (streq(done, "/"))
10991099
*done = '\0';
11001100

1101-
if (!strextend(&done, first, NULL))
1101+
if (!strextend(&done, first))
11021102
return -ENOMEM;
11031103
}
11041104

src/basic/string-util.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -791,10 +791,10 @@ char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]) {
791791
return *ibuf;
792792
}
793793

794-
char *strextend_with_separator(char **x, const char *separator, ...) {
795-
bool need_separator;
794+
char *strextend_with_separator_internal(char **x, const char *separator, ...) {
796795
size_t f, l, l_separator;
797-
char *r, *p;
796+
bool need_separator;
797+
char *nr, *p;
798798
va_list ap;
799799

800800
assert(x);
@@ -818,7 +818,7 @@ char *strextend_with_separator(char **x, const char *separator, ...) {
818818
if (need_separator)
819819
n += l_separator;
820820

821-
if (n > ((size_t) -1) - l) {
821+
if (n >= SIZE_MAX - l) {
822822
va_end(ap);
823823
return NULL;
824824
}
@@ -830,11 +830,12 @@ char *strextend_with_separator(char **x, const char *separator, ...) {
830830

831831
need_separator = !isempty(*x);
832832

833-
r = realloc(*x, l+1);
834-
if (!r)
833+
nr = realloc(*x, l+1);
834+
if (!nr)
835835
return NULL;
836836

837-
p = r + f;
837+
*x = nr;
838+
p = nr + f;
838839

839840
va_start(ap, separator);
840841
for (;;) {
@@ -853,12 +854,11 @@ char *strextend_with_separator(char **x, const char *separator, ...) {
853854
}
854855
va_end(ap);
855856

856-
assert(p == r + l);
857+
assert(p == nr + l);
857858

858859
*p = 0;
859-
*x = r;
860860

861-
return r + l;
861+
return p;
862862
}
863863

864864
char *strrep(const char *s, unsigned n) {

src/basic/string-util.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ char *strreplace(const char *text, const char *old_string, const char *new_strin
189189

190190
char *strip_tab_ansi(char **ibuf, size_t *_isz, size_t highlight[2]);
191191

192-
char *strextend_with_separator(char **x, const char *separator, ...) _sentinel_;
192+
char *strextend_with_separator_internal(char **x, const char *separator, ...) _sentinel_;
193193

194-
#define strextend(x, ...) strextend_with_separator(x, NULL, __VA_ARGS__)
194+
#define strextend_with_separator(x, separator, ...) strextend_with_separator_internal(x, separator, __VA_ARGS__, NULL)
195+
#define strextend(x, ...) strextend_with_separator_internal(x, NULL, __VA_ARGS__, NULL)
195196

196197
char *strrep(const char *s, unsigned n);
197198

src/busctl/busctl-introspect.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
406406

407407
if (argument_type) {
408408
if (!argument_direction || streq(argument_direction, "in")) {
409-
if (!strextend(&context->member_signature, argument_type, NULL))
409+
if (!strextend(&context->member_signature, argument_type))
410410
return log_oom();
411411
} else if (streq(argument_direction, "out")) {
412-
if (!strextend(&context->member_result, argument_type, NULL))
412+
if (!strextend(&context->member_result, argument_type))
413413
return log_oom();
414414
} else
415415
log_error("Unexpected method <arg> direction value '%s'.", argument_direction);
@@ -541,7 +541,7 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
541541

542542
if (argument_type) {
543543
if (!argument_direction || streq(argument_direction, "out")) {
544-
if (!strextend(&context->member_signature, argument_type, NULL))
544+
if (!strextend(&context->member_signature, argument_type))
545545
return log_oom();
546546
} else
547547
log_error("Unexpected signal <arg> direction value '%s'.", argument_direction);

src/core/device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ static int device_found_to_string_many(DeviceFound flags, char **ret) {
201201
if (!FLAGS_SET(flags, device_found_map[i].flag))
202202
continue;
203203

204-
if (!strextend_with_separator(&s, ",", device_found_map[i].name, NULL))
204+
if (!strextend_with_separator(&s, ",", device_found_map[i].name))
205205
return -ENOMEM;
206206
}
207207

src/core/killall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void log_children_no_yet_killed(Set *pids) {
8787
if (get_process_comm(PTR_TO_PID(p), &s) < 0)
8888
(void) asprintf(&s, PID_FMT, PTR_TO_PID(p));
8989

90-
if (!strextend(&lst_child, ", ", s, NULL)) {
90+
if (!strextend(&lst_child, ", ", s)) {
9191
log_oom();
9292
return;
9393
}

src/fstab-generator/fstab-generator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
843843
if (proc_cmdline_value_missing(key, value))
844844
return 0;
845845

846-
if (!strextend_with_separator(&arg_root_options, ",", value, NULL))
846+
if (!strextend_with_separator(&arg_root_options, ",", value))
847847
return log_oom();
848848

849849
} else if (streq(key, "roothash")) {
@@ -875,7 +875,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
875875
if (proc_cmdline_value_missing(key, value))
876876
return 0;
877877

878-
if (!strextend_with_separator(&arg_usr_options, ",", value, NULL))
878+
if (!strextend_with_separator(&arg_usr_options, ",", value))
879879
return log_oom();
880880

881881
} else if (streq(key, "rw") && !value)

src/hibernate-resume/hibernate-resume-generator.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
4545
if (proc_cmdline_value_missing(key, value))
4646
return 0;
4747

48-
if (!strextend_with_separator(&arg_resume_options, ",", value, NULL))
48+
if (!strextend_with_separator(&arg_resume_options, ",", value))
4949
return log_oom();
5050

5151
} else if (streq(key, "rootflags")) {
5252

5353
if (proc_cmdline_value_missing(key, value))
5454
return 0;
5555

56-
if (!strextend_with_separator(&arg_root_options, ",", value, NULL))
56+
if (!strextend_with_separator(&arg_root_options, ",", value))
5757
return log_oom();
5858

5959
} else if (streq(key, "noresume")) {

src/libsystemd/sd-bus/bus-message.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
14711471
if (c->enclosing != 0)
14721472
return -ENXIO;
14731473

1474-
e = strextend(&c->signature, CHAR_TO_STR(type), NULL);
1474+
e = strextend(&c->signature, CHAR_TO_STR(type));
14751475
if (!e) {
14761476
m->poisoned = true;
14771477
return -ENOMEM;
@@ -1664,7 +1664,7 @@ _public_ int sd_bus_message_append_string_space(
16641664
if (c->enclosing != 0)
16651665
return -ENXIO;
16661666

1667-
e = strextend(&c->signature, CHAR_TO_STR(SD_BUS_TYPE_STRING), NULL);
1667+
e = strextend(&c->signature, CHAR_TO_STR(SD_BUS_TYPE_STRING));
16681668
if (!e) {
16691669
m->poisoned = true;
16701670
return -ENOMEM;
@@ -1768,7 +1768,7 @@ static int bus_message_open_array(
17681768

17691769
/* Extend the existing signature */
17701770

1771-
e = strextend(&c->signature, CHAR_TO_STR(SD_BUS_TYPE_ARRAY), contents, NULL);
1771+
e = strextend(&c->signature, CHAR_TO_STR(SD_BUS_TYPE_ARRAY), contents);
17721772
if (!e) {
17731773
m->poisoned = true;
17741774
return -ENOMEM;
@@ -1853,7 +1853,7 @@ static int bus_message_open_variant(
18531853
if (c->enclosing != 0)
18541854
return -ENXIO;
18551855

1856-
e = strextend(&c->signature, CHAR_TO_STR(SD_BUS_TYPE_VARIANT), NULL);
1856+
e = strextend(&c->signature, CHAR_TO_STR(SD_BUS_TYPE_VARIANT));
18571857
if (!e) {
18581858
m->poisoned = true;
18591859
return -ENOMEM;
@@ -1921,7 +1921,7 @@ static int bus_message_open_struct(
19211921
if (c->enclosing != 0)
19221922
return -ENXIO;
19231923

1924-
e = strextend(&c->signature, CHAR_TO_STR(SD_BUS_TYPE_STRUCT_BEGIN), contents, CHAR_TO_STR(SD_BUS_TYPE_STRUCT_END), NULL);
1924+
e = strextend(&c->signature, CHAR_TO_STR(SD_BUS_TYPE_STRUCT_BEGIN), contents, CHAR_TO_STR(SD_BUS_TYPE_STRUCT_END));
19251925
if (!e) {
19261926
m->poisoned = true;
19271927
return -ENOMEM;
@@ -2776,7 +2776,7 @@ _public_ int sd_bus_message_append_string_memfd(
27762776
if (c->enclosing != 0)
27772777
return -ENXIO;
27782778

2779-
e = strextend(&c->signature, CHAR_TO_STR(SD_BUS_TYPE_STRING), NULL);
2779+
e = strextend(&c->signature, CHAR_TO_STR(SD_BUS_TYPE_STRING));
27802780
if (!e) {
27812781
m->poisoned = true;
27822782
return -ENOMEM;

0 commit comments

Comments
 (0)
X Tutup