]> git.ipfire.org Git - people/ms/pakfire.git/commitdiff
jail: Refactor searching for env variable function
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 21 Jun 2023 13:31:27 +0000 (13:31 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 21 Jun 2023 13:31:27 +0000 (13:31 +0000)
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 <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index ed669d4994d94158bc03b0f30bc7db2fe31e04ce..c3a864f19b48f7dd27583f73b4b2655132dcc217 100644 (file)
@@ -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