1
0
mirror of https://github.com/systemd/systemd synced 2024-07-03 08:29:25 +00:00

strv: replace always-true condition with assertion

Follow-up for aca093018c.
Fixes CID#1547105.
This commit is contained in:
Yu Watanabe 2024-06-18 18:12:39 +09:00 committed by Luca Boccassi
parent 07748c53df
commit f2d2aa0934

View File

@ -1053,20 +1053,20 @@ int strv_rebreak_lines(char **l, size_t width, char ***ret) {
} }
} }
if (start) { /* Process rest of the line */ /* Process rest of the line */
if (in_prefix) /* Never seen anything non-whitespace? Generate empty line! */ assert(start);
r = strv_extend(&broken, ""); if (in_prefix) /* Never seen anything non-whitespace? Generate empty line! */
else if (whitespace_begin && !whitespace_end) { /* Ends in whitespace? Chop it off! */ r = strv_extend(&broken, "");
_cleanup_free_ char *truncated = strndup(start, whitespace_begin - start); else if (whitespace_begin && !whitespace_end) { /* Ends in whitespace? Chop it off! */
if (!truncated) _cleanup_free_ char *truncated = strndup(start, whitespace_begin - start);
return -ENOMEM; if (!truncated)
return -ENOMEM;
r = strv_consume(&broken, TAKE_PTR(truncated)); r = strv_consume(&broken, TAKE_PTR(truncated));
} else /* Otherwise use line as is */ } else /* Otherwise use line as is */
r = strv_extend(&broken, start); r = strv_extend(&broken, start);
if (r < 0) if (r < 0)
return r; return r;
}
} }
*ret = TAKE_PTR(broken); *ret = TAKE_PTR(broken);