This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Minor cleanup in getaddrinfo
- From: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Thu, 18 Apr 2013 17:17:45 +0530
- Subject: [PATCH] Minor cleanup in getaddrinfo
Hi,
Here's a trivial cleanup that replaces repeated computations of alloca
size with a local variable that stores the computed value. OK to
commit?
Siddhesh
* sysdeps/posix/getaddrinfo.c (getaddrinfo): Compute results
size just once.
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index 2309281..d368306 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -2495,12 +2495,13 @@ getaddrinfo (const char *name, const char *service,
struct addrinfo *last = NULL;
char *canonname = NULL;
bool malloc_results;
+ size_t alloc_size = nresults * (sizeof (*results) + sizeof (size_t));
malloc_results
- = !__libc_use_alloca (nresults * (sizeof (*results) + sizeof (size_t)));
+ = !__libc_use_alloca (alloc_size);
if (malloc_results)
{
- results = malloc (nresults * (sizeof (*results) + sizeof (size_t)));
+ results = malloc (alloc_size);
if (results == NULL)
{
__free_in6ai (in6ai);
@@ -2508,7 +2509,7 @@ getaddrinfo (const char *name, const char *service,
}
}
else
- results = alloca (nresults * (sizeof (*results) + sizeof (size_t)));
+ results = alloca (alloc_size);
order = (size_t *) (results + nresults);
/* Now we definitely need the interface information. */