1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-10 05:18:17 +03:00

network/sysctl-monitor: fix sanity check in cut_last()

This also adds basic comment about the return code.

Follow-up for 6d9ef22acd.
This commit is contained in:
Yu Watanabe 2024-09-16 09:19:21 +09:00
parent 9671efff78
commit 41afafbf2a

View File

@ -36,23 +36,22 @@ struct str {
static long cut_last(u32 i, struct str *str) {
char *s;
/* Sanity check for the preverifier */
if (i >= str->l)
return 1; /* exit from the loop */
i = str->l - i - 1;
s = str->s + i;
/* Sanity check for the preverifier */
if (i >= str->l)
return 1;
if (*s == 0)
return 0;
return 0; /* continue */
if (*s == '\n' || *s == '\r' || *s == ' ' || *s == '\t') {
*s = 0;
return 0;
return 0; /* continue */
}
return 1;
return 1; /* exit from the loop */
}
/* Cut off trailing whitespace and newlines */