fs-util: make sure openat_report_new() initializes return param also on shortcut

Our coding style dictates that return parameters should be initialized
always on success, hence do so here also in the shortcut codepath.

Issue discovered by @fbuihuu:

https://github.com/systemd/systemd/pull/22808/files/ca8503f168d0632c606110da909aba3057777395#r831911069
This commit is contained in:
Lennart Poettering
2022-03-23 11:38:08 +09:00
committed by Yu Watanabe
parent b312236919
commit 4d5dacbef3
2 changed files with 29 additions and 3 deletions
+18
View File
@@ -1018,6 +1018,24 @@ TEST(openat_report_new) {
assert_se(fd >= 0);
fd = safe_close(fd);
assert_se(!b);
fd = openat_report_new(AT_FDCWD, j, O_RDWR, 0666, &b);
assert_se(fd >= 0);
fd = safe_close(fd);
assert_se(!b);
fd = openat_report_new(AT_FDCWD, j, O_RDWR|O_CREAT|O_EXCL, 0666, &b);
assert_se(fd == -EEXIST);
assert_se(unlink(j) >= 0);
fd = openat_report_new(AT_FDCWD, j, O_RDWR, 0666, &b);
assert_se(fd == -ENOENT);
fd = openat_report_new(AT_FDCWD, j, O_RDWR|O_CREAT|O_EXCL, 0666, &b);
assert_se(fd >= 0);
fd = safe_close(fd);
assert_se(b);
}
static int intro(void) {