From 7a005aa96b509441fe29fff57541e6d7be61afbb Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 28 Dec 2022 13:22:36 -0600 Subject: [PATCH] break out after reading the value This is a small optimization, it avoids reading the full file when an early key is requested. In the case of an *invalid* TOML file such as ``` K=80 K=81 ``` this stops the value of K actually returned being 8081 and makes it 80 instead; but as it's a malformed file it doesn't really matter much. --- shared-module/os/getenv.c | 1 + 1 file changed, 1 insertion(+) diff --git a/shared-module/os/getenv.c b/shared-module/os/getenv.c index aac87e9ee6..870973c5d2 100644 --- a/shared-module/os/getenv.c +++ b/shared-module/os/getenv.c @@ -292,6 +292,7 @@ STATIC os_getenv_err_t os_getenv_vstr(const char *path, const char *key, vstr_t while (!is_eof(&active_file)) { if (key_matches(&active_file, key)) { result = read_value(&active_file, buf, quoted); + break; } } close_file(&active_file);