summaryrefslogtreecommitdiff
path: root/src/nss-myhostname/nss-myhostname.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-04-05 22:24:10 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-04-10 18:59:42 -0400
commit1c6330456c5ae76085c63d2a7cf3d722596e545a (patch)
tree3b6a50e4fd7e7342679b3deb0f254b545567e7f5 /src/nss-myhostname/nss-myhostname.c
parent0affed79d2e30013f07cb94e6f07e3fcb81c02fa (diff)
Use initalization instead of explicit zeroing in more places
Diffstat (limited to 'src/nss-myhostname/nss-myhostname.c')
-rw-r--r--src/nss-myhostname/nss-myhostname.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/nss-myhostname/nss-myhostname.c b/src/nss-myhostname/nss-myhostname.c
index b0fb8323ad..2dd3d4a57c 100644
--- a/src/nss-myhostname/nss-myhostname.c
+++ b/src/nss-myhostname/nss-myhostname.c
@@ -32,6 +32,8 @@
#include <arpa/inet.h>
#include "ifconf.h"
+#include "macro.h"
+#include "util.h"
/* We use 127.0.0.2 as IPv4 address. This has the advantage over
* 127.0.0.1 that it can be translated back to the local hostname. For
@@ -42,8 +44,6 @@
#define LOCALADDRESS_IPV6 &in6addr_loopback
#define LOOPBACK_INTERFACE "lo"
-#define ALIGN(a) (((a+sizeof(void*)-1)/sizeof(void*))*sizeof(void*))
-
enum nss_status _nss_myhostname_gethostbyname4_r(
const char *name,
struct gaih_addrtuple **pat,
@@ -96,14 +96,13 @@ enum nss_status _nss_myhostname_gethostbyname4_r(
int32_t *ttlp) {
unsigned lo_ifi;
- char hn[HOST_NAME_MAX+1];
+ char hn[HOST_NAME_MAX+1] = {};
size_t l, idx, ms;
char *r_name;
struct gaih_addrtuple *r_tuple, *r_tuple_prev = NULL;
struct address *addresses = NULL, *a;
unsigned n_addresses = 0, n;
- memset(hn, 0, sizeof(hn));
if (gethostname(hn, sizeof(hn)-1) < 0) {
*errnop = errno;
*h_errnop = NO_RECOVERY;
@@ -312,7 +311,7 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
int32_t *ttlp,
char **canonp) {
- char hn[HOST_NAME_MAX+1];
+ char hn[HOST_NAME_MAX+1] = {};
if (af == AF_UNSPEC)
af = AF_INET;
@@ -323,7 +322,6 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
return NSS_STATUS_UNAVAIL;
}
- memset(hn, 0, sizeof(hn));
if (gethostname(hn, sizeof(hn)-1) < 0) {
*errnop = errno;
*h_errnop = NO_RECOVERY;
@@ -380,8 +378,9 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r(
int *errnop, int *h_errnop,
int32_t *ttlp) {
- char hn[HOST_NAME_MAX+1];
- struct address *addresses = NULL, *a;
+ char hn[HOST_NAME_MAX+1] = {};
+ struct address _cleanup_free_ *addresses = NULL;
+ struct address *a;
unsigned n_addresses = 0, n;
if (len != PROTO_ADDRESS_SIZE(af)) {
@@ -419,13 +418,9 @@ enum nss_status _nss_myhostname_gethostbyaddr2_r(
*errnop = ENOENT;
*h_errnop = HOST_NOT_FOUND;
- free(addresses);
return NSS_STATUS_NOTFOUND;
found:
- free(addresses);
-
- memset(hn, 0, sizeof(hn));
if (gethostname(hn, sizeof(hn)-1) < 0) {
*errnop = errno;
*h_errnop = NO_RECOVERY;