This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] getenv: Move call to strlen to the branch it's used in.
- From: Lode Willems <Lode dot Willems at UGent dot be>
- To: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Date: Sat, 2 Nov 2019 09:58:50 +0000
- Subject: [PATCH] getenv: Move call to strlen to the branch it's used in.
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ugent.be; dmarc=pass action=none header.from=ugent.be; dkim=pass header.d=ugent.be; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=3CQt6wYTbVv8xufdwTnoUaGcsFBKI/UkxhN/S288DOk=; b=HmYjALTSJXa4v6q+chHvBotTosPirGfbSujNGgbGTEThFCRCgNWQKgKRKUni2+ib98i4k78G1ZFD3Icauno3Zzt6OUEiIBWxN8UwMqhSTyIsqk/mOKvK4q9wxPjukmZPl2CwECF1dq22wEKZijQbElG8nwcQiYxeroC1H61Psrg1Hht0OXLIfziff6gir2FqeTJHCxB4nXYZ1GUX/kkta7MOdVXHcpXkQx+lPcGh/jaWHoX8R6Ornm1W0dHVqrw0QQhJOAee8n/b/fvNMihZfl7CEoYRC8wNqZUxthMA0w1TGe3RJxxuvDF/WC/xPnPpJgtknhNyv0e+CKxf0EyZHA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cHxe8FwMR4RSxHRv0aVZPX+Q3e+S0KHg0GeQTCUu5gW7p49wcgZvoSMSDX9BF033JBEvh4QrwSMcx9/t0k03e2AQaJGARI07csq6Kg7PzCPVTV9v3x1TvW80h+oPupKLdKX8nxNevWsUCwZGf8m3u7W8+4CU4xk6Ep0BhXPXVJ3JgMRtErOwf1V5UohNnY+u4I8LamIg6ZOvi+Hhz3iGxVGnnxy1GJtwhcWmJKjlHp/aeQ6izt6BuYnpmtrBRxZ/ADyuFjZgC0qiUsoQllZzUedzWQyM80RJ5gcjbaOBujPRM/zrOtkrN/TdIZmyPAgasjYCYtGIanbVLMTPc3vP7g==
The len variable is only used in the else branch.
We don't need the call to strlen if the name is 0 or 1 characters long.
2019-10-02 Lode Willems <Lode.Willems@UGent.be>
* tdlib/getenv.c: Move the call to strlen into the branch it's used.
diff --git a/stdlib/getenv.c b/stdlib/getenv.c
index 6be97b2a54..aa5e69d0b0 100644
--- a/stdlib/getenv.c
+++ b/stdlib/getenv.c
@@ -32,7 +32,6 @@
char *
getenv (const char *name)
{
- size_t len = strlen (name);
char **ep;
uint16_t name_start;
@@ -63,6 +62,7 @@ getenv (const char *name)
}
else
{
+ size_t len = strlen (name);
#if _STRING_ARCH_unaligned
name_start = *(const uint16_t *) name;
#else