summaryrefslogtreecommitdiff
path: root/src/nss-myhostname/nss-myhostname.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-07-11 15:34:18 +0200
committerLennart Poettering <lennart@poettering.net>2014-07-11 15:35:22 +0200
commitd4c9895d93700d20b7d092244a278009789d8e74 (patch)
tree4d9459554269e3e1521fdf43b8f0dfbab845cf41 /src/nss-myhostname/nss-myhostname.c
parentd77ab3f7e3e56a4fd370caff6347bf4e56e51dec (diff)
nss-myhostname: simplify array building a bit
Diffstat (limited to 'src/nss-myhostname/nss-myhostname.c')
-rw-r--r--src/nss-myhostname/nss-myhostname.c23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c
index 06bd842fc6..23646e6e8a 100644
--- a/src/nss-myhostname/nss-myhostname.c
+++ b/src/nss-myhostname/nss-myhostname.c
@@ -184,9 +184,8 @@ static enum nss_status fill_in_hostent(
int32_t *ttlp,
char **canonp) {
- size_t l_canonical, l_additional, idx, ms;
+ size_t l_canonical, l_additional, idx, ms, alen;
char *r_addr, *r_name, *r_aliases, *r_alias = NULL, *r_addr_list;
- size_t alen;
struct local_address *a;
unsigned n, c;
@@ -208,7 +207,7 @@ static enum nss_status fill_in_hostent(
(additional ? ALIGN(l_additional+1) : 0) +
sizeof(char*) +
(additional ? sizeof(char*) : 0) +
- (c > 0 ? c : 1) * ALIGN(alen)+
+ (c > 0 ? c : 1) * ALIGN(alen) +
(c > 0 ? c+1 : 2) * sizeof(char*);
if (buflen < ms) {
@@ -266,24 +265,18 @@ static enum nss_status fill_in_hostent(
/* Fourth, add address pointer array */
r_addr_list = buffer + idx;
if (c > 0) {
- unsigned i = 0;
+ unsigned i;
- for (a = addresses, n = 0; n < n_addresses; a++, n++) {
- if (af != a->family)
- continue;
+ for (i = 0; i < c; i++)
+ ((char**) r_addr_list)[i] = r_addr + i*ALIGN(alen);
- ((char**) r_addr_list)[i] = (r_addr + i*ALIGN(alen));
- i++;
- }
-
- assert(i == c);
- ((char**) r_addr_list)[c] = NULL;
- idx += (c+1)*sizeof(char*);
+ ((char**) r_addr_list)[i] = NULL;
+ idx += (c+1) * sizeof(char*);
} else {
((char**) r_addr_list)[0] = r_addr;
((char**) r_addr_list)[1] = NULL;
- idx += 2*sizeof(char*);
+ idx += 2 * sizeof(char*);
}
/* Verify the size matches */