various: use strdup_to() in various obvious cases

strdup_to() returns 0 on success and here we convert obvious blocks
which either return -ENOMEM or 0.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2024-03-20 15:13:44 +01:00
parent 7e850da3d6
commit 454318d3e8
17 changed files with 31 additions and 124 deletions
+2 -7
View File
@@ -25,7 +25,7 @@ int format_ifname_full(int ifindex, FormatIfnameFlag flag, char buf[static IF_NA
}
int format_ifname_full_alloc(int ifindex, FormatIfnameFlag flag, char **ret) {
char buf[IF_NAMESIZE], *copy;
char buf[IF_NAMESIZE];
int r;
assert(ret);
@@ -34,12 +34,7 @@ int format_ifname_full_alloc(int ifindex, FormatIfnameFlag flag, char **ret) {
if (r < 0)
return r;
copy = strdup(buf);
if (!copy)
return -ENOMEM;
*ret = copy;
return 0;
return strdup_to(ret, buf);
}
char *format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag) {