From: Michael Tremer Date: Wed, 21 Jun 2023 13:31:27 +0000 (+0000) Subject: jail: Refactor searching for env variable function X-Git-Tag: 0.9.29~110 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b88ae806b1d3b879c30b51c7f4c5689809e52be4;p=pakfire.git jail: Refactor searching for env variable function This used a variable size array on the stack before which is not needed. This version should be slightly faster and the compiler should be able to inline it. Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index ed669d499..c3a864f19 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -370,12 +370,13 @@ static int pakfire_jail_find_env(struct pakfire_jail* jail, const char* key) { return -1; } - char buffer[strlen(key) + 2]; - pakfire_string_format(buffer, "%s=", key); + const size_t length = strlen(key); for (unsigned int i = 0; jail->env[i]; i++) { - if (pakfire_string_startswith(jail->env[i], buffer)) + if ((pakfire_string_startswith(jail->env[i], key) + && *(jail->env[i] + length) == '=')) { return i; + } } // Nothing found