summaryrefslogtreecommitdiffstats
path: root/src/test/test-copy.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-04-29 14:25:52 +0200
committerLennart Poettering <lennart@poettering.net>2016-04-29 14:28:04 +0200
commit2397bc4312f6d1fbdf97bf826a1ca6ad409aabf3 (patch)
tree17a41ea1d7e3b2f218cfc203848fdc2bbcde6553 /src/test/test-copy.c
parentcopy: also copy AF_UNIX sockets (diff)
downloadsystemd-2397bc4312f6d1fbdf97bf826a1ca6ad409aabf3.tar.xz
systemd-2397bc4312f6d1fbdf97bf826a1ca6ad409aabf3.zip
test-copy: never call alloca() in a loop
That's a total no-no, hence rework this to use malloc()-based memory instead of alloca()-based memory. Also see CODING_STYLE about this.
Diffstat (limited to '')
-rw-r--r--src/test/test-copy.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/test/test-copy.c b/src/test/test-copy.c
index d1bf376385..68154fc4e8 100644
--- a/src/test/test-copy.c
+++ b/src/test/test-copy.c
@@ -104,15 +104,19 @@ static void test_copy_tree(void) {
(void) rm_rf(original_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
STRV_FOREACH(p, files) {
- char *f = strjoina(original_dir, *p);
+ _cleanup_free_ char *f;
+
+ assert_se(f = strappend(original_dir, *p));
assert_se(mkdir_parents(f, 0755) >= 0);
assert_se(write_string_file(f, "file", WRITE_STRING_FILE_CREATE) == 0);
}
STRV_FOREACH_PAIR(link, p, links) {
- char *f = strjoina(original_dir, *p);
- char *l = strjoina(original_dir, *link);
+ _cleanup_free_ char *f, *l;
+
+ assert_se(f = strappend(original_dir, *p));
+ assert_se(l = strappend(original_dir, *link));
assert_se(mkdir_parents(l, 0755) >= 0);
assert_se(symlink(f, l) == 0);
@@ -124,9 +128,10 @@ static void test_copy_tree(void) {
assert_se(copy_tree(original_dir, copy_dir, true) == 0);
STRV_FOREACH(p, files) {
- _cleanup_free_ char *buf = NULL;
+ _cleanup_free_ char *buf = NULL, *f;
size_t sz = 0;
- char *f = strjoina(copy_dir, *p);
+
+ assert_se(f = strappend(copy_dir, *p));
assert_se(access(f, F_OK) == 0);
assert_se(read_full_file(f, &buf, &sz) == 0);
@@ -134,9 +139,10 @@ static void test_copy_tree(void) {
}
STRV_FOREACH_PAIR(link, p, links) {
- _cleanup_free_ char *target = NULL;
- char *f = strjoina(original_dir, *p);
- char *l = strjoina(copy_dir, *link);
+ _cleanup_free_ char *target = NULL, *f, *l;
+
+ assert_se(f = strjoin(original_dir, *p, NULL));
+ assert_se(l = strjoin(copy_dir, *link, NULL));
assert_se(readlink_and_canonicalize(l, &target) == 0);
assert_se(path_equal(f, target));