diff options
author | delphij <delphij@FreeBSD.org> | 2008-10-23 00:15:00 +0000 |
---|---|---|
committer | delphij <delphij@FreeBSD.org> | 2008-10-23 00:15:00 +0000 |
commit | 5aab1041be4db942ac52eef4b61cffc6ec3f52ef (patch) | |
tree | 16a0f59db102b3c13cfd79f02ae44084875ddf6f /usr.sbin/nscd | |
parent | d2358aab518c50cffb131feeefa641cad349a8ee (diff) | |
download | FreeBSD-src-5aab1041be4db942ac52eef4b61cffc6ec3f52ef.zip FreeBSD-src-5aab1041be4db942ac52eef4b61cffc6ec3f52ef.tar.gz |
Replace malloc() + memset() with calloc. This corrects a misuse of
memset() as a side effect.
Diffstat (limited to 'usr.sbin/nscd')
-rw-r--r-- | usr.sbin/nscd/agents/group.c | 9 | ||||
-rw-r--r-- | usr.sbin/nscd/agents/passwd.c | 9 | ||||
-rw-r--r-- | usr.sbin/nscd/agents/services.c | 12 |
3 files changed, 10 insertions, 20 deletions
diff --git a/usr.sbin/nscd/agents/group.c b/usr.sbin/nscd/agents/group.c index b9190be..ba61db7 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 50c55ba..b068d19 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 b0a2eb9..44dec39 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; |