diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-05-14 09:48:50 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-05-14 12:18:48 +0200 |
commit | 73a8d8b0ca4569568aa1bc5883d4953b3f69d1f1 (patch) | |
tree | f64812abe7badab84d74d1d9aae8c5dd4c1e4711 | |
parent | shared/bootspec: add missing assertions (diff) | |
download | systemd-73a8d8b0ca4569568aa1bc5883d4953b3f69d1f1.tar.xz systemd-73a8d8b0ca4569568aa1bc5883d4953b3f69d1f1.zip |
shared/bootspec: inline iterator var
Also, do not bump 'line' until the end of the loop.
Otherwise, log_syntax() below logs about the wrong
line number.
-rw-r--r-- | src/shared/bootspec.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 9e8064b2be..882d026a40 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -289,7 +289,6 @@ static int boot_entry_load_type1( BootEntry *entry) { _cleanup_(boot_entry_free) BootEntry tmp = BOOT_ENTRY_INIT(BOOT_ENTRY_CONF); - unsigned line = 1; char *c; int r; @@ -324,18 +323,16 @@ static int boot_entry_load_type1( if (!tmp.root) return log_oom(); - for (;;) { + for (unsigned line = 1;; line++) { _cleanup_free_ char *buf = NULL, *field = NULL; r = read_stripped_line(f, LONG_LINE_MAX, &buf); - if (r == 0) - break; if (r == -ENOBUFS) return log_syntax(NULL, LOG_ERR, tmp.path, line, r, "Line too long."); if (r < 0) return log_syntax(NULL, LOG_ERR, tmp.path, line, r, "Error while reading: %m"); - - line++; + if (r == 0) + break; if (IN_SET(buf[0], '#', '\0')) continue; @@ -436,25 +433,22 @@ void boot_config_free(BootConfig *config) { } int boot_loader_read_conf(BootConfig *config, FILE *file, const char *path) { - unsigned line = 1; int r; assert(config); assert(file); assert(path); - for (;;) { + for (unsigned line = 1;; line++) { _cleanup_free_ char *buf = NULL, *field = NULL; r = read_stripped_line(file, LONG_LINE_MAX, &buf); - if (r == 0) - break; if (r == -ENOBUFS) return log_syntax(NULL, LOG_ERR, path, line, r, "Line too long."); if (r < 0) return log_syntax(NULL, LOG_ERR, path, line, r, "Error while reading: %m"); - - line++; + if (r == 0) + break; if (IN_SET(buf[0], '#', '\0')) continue; |