aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2008-10-23 00:15:00 +0000
committerXin LI <delphij@FreeBSD.org>2008-10-23 00:15:00 +0000
commit9bbd8028fa77bd549aba5fecf5eb872bf0832a32 (patch)
tree16a0f59db102b3c13cfd79f02ae44084875ddf6f /usr.sbin
parent59e2759db82d62c1f79e798c57e7fa7c157ec8ee (diff)
downloadsrc-9bbd8028fa77bd549aba5fecf5eb872bf0832a32.tar.gz
src-9bbd8028fa77bd549aba5fecf5eb872bf0832a32.zip
Replace malloc() + memset() with calloc. This corrects a misuse of
memset() as a side effect.
Notes
Notes: svn path=/head/; revision=184186
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/nscd/agents/group.c9
-rw-r--r--usr.sbin/nscd/agents/passwd.c9
-rw-r--r--usr.sbin/nscd/agents/services.c12
3 files changed, 10 insertions, 20 deletions
diff --git a/usr.sbin/nscd/agents/group.c b/usr.sbin/nscd/agents/group.c
index b9190be44849..ba61db7f56f9 100644
--- a/usr.sbin/nscd/agents/group.c
+++ b/usr.sbin/nscd/agents/group.c
@@ -140,9 +140,8 @@ group_lookup_func(const char *key, size_t key_size, char **buffer,
switch (lookup_type) {
case nss_lt_name:
size = key_size - sizeof(enum nss_lookup_type) + 1;
- name = (char *)malloc(size);
+ name = (char *)calloc(1, size);
assert(name != NULL);
- memset(name, 0, size);
memcpy(name, key + sizeof(enum nss_lookup_type), size - 1);
break;
case nss_lt_id:
@@ -225,9 +224,8 @@ init_group_agent()
struct common_agent *retval;
TRACE_IN(init_group_agent);
- retval = (struct common_agent *)malloc(sizeof(struct common_agent));
+ retval = (struct common_agent *)calloc(1, sizeof(struct common_agent));
assert(retval != NULL);
- memset(retval, 0, sizeof(struct common_agent));
retval->parent.name = strdup("group");
assert(retval->parent.name != NULL);
@@ -245,10 +243,9 @@ init_group_mp_agent()
struct multipart_agent *retval;
TRACE_IN(init_group_mp_agent);
- retval = (struct multipart_agent *)malloc(
+ retval = (struct multipart_agent *)calloc(1,
sizeof(struct multipart_agent));
assert(retval != NULL);
- memset(retval, 0, sizeof(struct multipart_agent));
retval->parent.name = strdup("group");
retval->parent.type = MULTIPART_AGENT;
diff --git a/usr.sbin/nscd/agents/passwd.c b/usr.sbin/nscd/agents/passwd.c
index 50c55babc633..b068d1992fed 100644
--- a/usr.sbin/nscd/agents/passwd.c
+++ b/usr.sbin/nscd/agents/passwd.c
@@ -148,9 +148,8 @@ passwd_lookup_func(const char *key, size_t key_size, char **buffer,
switch (lookup_type) {
case nss_lt_name:
size = key_size - sizeof(enum nss_lookup_type) + 1;
- login = (char *)malloc(size);
+ login = (char *)calloc(1, size);
assert(login != NULL);
- memset(login, 0, size);
memcpy(login, key + sizeof(enum nss_lookup_type), size - 1);
break;
case nss_lt_id:
@@ -232,9 +231,8 @@ init_passwd_agent()
struct common_agent *retval;
TRACE_IN(init_passwd_agent);
- retval = (struct common_agent *)malloc(sizeof(struct common_agent));
+ retval = (struct common_agent *)calloc(1, sizeof(struct common_agent));
assert(retval != NULL);
- memset(retval, 0, sizeof(struct common_agent));
retval->parent.name = strdup("passwd");
assert(retval->parent.name != NULL);
@@ -252,10 +250,9 @@ init_passwd_mp_agent()
struct multipart_agent *retval;
TRACE_IN(init_passwd_mp_agent);
- retval = (struct multipart_agent *)malloc(
+ retval = (struct multipart_agent *)calloc(1,
sizeof(struct multipart_agent));
assert(retval != NULL);
- memset(retval, 0, sizeof(struct multipart_agent));
retval->parent.name = strdup("passwd");
retval->parent.type = MULTIPART_AGENT;
diff --git a/usr.sbin/nscd/agents/services.c b/usr.sbin/nscd/agents/services.c
index b0a2eb99fad8..44dec39c3d25 100644
--- a/usr.sbin/nscd/agents/services.c
+++ b/usr.sbin/nscd/agents/services.c
@@ -145,9 +145,8 @@ services_lookup_func(const char *key, size_t key_size, char **buffer,
switch (lookup_type) {
case nss_lt_name:
size = key_size - sizeof(enum nss_lookup_type);
- name = (char *)malloc(size + 1);
+ name = (char *)calloc(1, size + 1);
assert(name != NULL);
- memset(name, 0, size + 1);
memcpy(name, key + sizeof(enum nss_lookup_type), size);
size2 = strlen(name) + 1;
@@ -169,9 +168,8 @@ services_lookup_func(const char *key, size_t key_size, char **buffer,
size = key_size - sizeof(enum nss_lookup_type) - sizeof(int);
if (size > 0) {
- proto = (char *)malloc(size + 1);
+ proto = (char *)calloc(1, size + 1);
assert(proto != NULL);
- memset(proto, size + 1, 0);
memcpy(proto, key + sizeof(enum nss_lookup_type) +
sizeof(int), size);
}
@@ -247,9 +245,8 @@ init_services_agent()
struct common_agent *retval;
TRACE_IN(init_services_agent);
- retval = (struct common_agent *)malloc(sizeof(struct common_agent));
+ retval = (struct common_agent *)calloc(1, sizeof(struct common_agent));
assert(retval != NULL);
- memset(retval, 0, sizeof(struct common_agent));
retval->parent.name = strdup("services");
assert(retval->parent.name != NULL);
@@ -267,10 +264,9 @@ init_services_mp_agent()
struct multipart_agent *retval;
TRACE_IN(init_services_mp_agent);
- retval = (struct multipart_agent *)malloc(
+ retval = (struct multipart_agent *)calloc(1,
sizeof(struct multipart_agent));
assert(retval != NULL);
- memset(retval, 0, sizeof(struct multipart_agent));
retval->parent.name = strdup("services");
retval->parent.type = MULTIPART_AGENT;