Re: [PATCH 7] npppd: malloc/memset = calloc

2014-05-29 Thread YASUOKA Masahiko
Thanks, commited.  

On Mon, 26 May 2014 22:24:23 +0200
Benjamin Baier program...@netzbasis.de wrote:
 and a big one.
 
 Index: common/bytebuf.c
 ===
 RCS file: /cvs/src/usr.sbin/npppd/common/bytebuf.c,v
 retrieving revision 1.5
 diff -u -p -r1.5 bytebuf.c
 --- common/bytebuf.c  8 May 2012 13:15:11 -   1.5
 +++ common/bytebuf.c  26 May 2014 20:16:32 -
 @@ -96,15 +96,12 @@ bytebuffer_create(size_t capacity)
  {
   bytebuffer *_this = NULL;
  
 - if ((_this = malloc(sizeof(bytebuffer))) == NULL)
 + if ((_this = calloc(1, sizeof(bytebuffer))) == NULL)
   return NULL;
  
 - memset(_this, 0, sizeof(bytebuffer));
 -
   if (capacity  0) {
 - if ((_this-data = malloc(capacity)) == NULL)
 + if ((_this-data = calloc(1, capacity)) == NULL)
   goto fail;
 - memset(_this-data, 0, capacity);
   _this-capacity = capacity;
   } else
   _this-capacity = 0;
 
 Index: npppd/npppd_auth.c
 ===
 RCS file: /cvs/src/usr.sbin/npppd/npppd/npppd_auth.c,v
 retrieving revision 1.13
 diff -u -p -r1.13 npppd_auth.c
 --- npppd/npppd_auth.c22 Mar 2014 04:23:17 -  1.13
 +++ npppd/npppd_auth.c26 May 2014 20:16:32 -
 @@ -73,8 +73,7 @@ npppd_auth_create(int auth_type, const c
  
   switch (auth_type) {
   case NPPPD_AUTH_TYPE_LOCAL:
 - if ((base = malloc(sizeof(npppd_auth_local))) != NULL) {
 - memset(base, 0, sizeof(npppd_auth_local));
 + if ((base = calloc(1, sizeof(npppd_auth_local))) != NULL) {
   base-type = NPPPD_AUTH_TYPE_LOCAL;
   base-strip_nt_domain = 1;
   base-strip_atmark_realm = 0;
 @@ -87,9 +86,8 @@ npppd_auth_create(int auth_type, const c
  
  #ifdef USE_NPPPD_RADIUS
   case NPPPD_AUTH_TYPE_RADIUS:
 - if ((base = malloc(sizeof(npppd_auth_radius))) != NULL) {
 + if ((base = calloc(1, sizeof(npppd_auth_radius))) != NULL) {
   npppd_auth_radius *_this = (npppd_auth_radius *)base;
 - memset(base, 0, sizeof(npppd_auth_radius));
   base-type = NPPPD_AUTH_TYPE_RADIUS;
   base-strip_nt_domain = 0;
   strlcpy(base-name, name, sizeof(base-name));
 
 Index: npppd/npppd_ctl.c
 ===
 RCS file: /cvs/src/usr.sbin/npppd/npppd/npppd_ctl.c,v
 retrieving revision 1.11
 diff -u -p -r1.11 npppd_ctl.c
 --- npppd/npppd_ctl.c 22 Mar 2014 04:30:31 -  1.11
 +++ npppd/npppd_ctl.c 26 May 2014 20:16:32 -
 @@ -71,9 +71,8 @@ npppd_ctl_create(npppd *_this)
  {
   struct npppd_ctl *ctl;
  
 - if ((ctl = malloc(sizeof(struct npppd_ctl))) == NULL)
 + if ((ctl = calloc(1, sizeof(struct npppd_ctl))) == NULL)
   return (NULL);
 - memset(ctl, 0, sizeof(struct npppd_ctl));
   ctl-npppd = _this;
   TAILQ_INIT(ctl-stopped_ppps);
  
 Index: npppd/ppp.c
 ===
 RCS file: /cvs/src/usr.sbin/npppd/npppd/ppp.c,v
 retrieving revision 1.20
 diff -u -p -r1.20 ppp.c
 --- npppd/ppp.c   22 Mar 2014 04:32:39 -  1.20
 +++ npppd/ppp.c   26 May 2014 20:16:32 -
 @@ -109,11 +109,10 @@ ppp_create()
  {
   npppd_ppp *_this;
  
 - if ((_this = malloc(sizeof(npppd_ppp))) == NULL) {
 - log_printf(LOG_ERR, malloc() failed in %s(): %m, __func__ );
 + if ((_this = calloc(1, sizeof(npppd_ppp))) == NULL) {
 + log_printf(LOG_ERR, calloc() failed in %s(): %m, __func__ );
   return NULL;
   }
 - memset(_this, 0, sizeof(npppd_ppp));
  
   _this-snp.snp_family = AF_INET;
   _this-snp.snp_len = sizeof(_this-snp);
 
 Index: npppd/radius_req.c
 ===
 RCS file: /cvs/src/usr.sbin/npppd/npppd/radius_req.c,v
 retrieving revision 1.7
 diff -u -p -r1.7 radius_req.c
 --- npppd/radius_req.c22 Mar 2014 04:25:00 -  1.7
 +++ npppd/radius_req.c26 May 2014 20:16:33 -
 @@ -275,11 +275,10 @@ radius_prepare(radius_req_setting *setti
  
   if (setting-server[setting-curr_server].enabled == 0)
   return 1;
 - if ((lap = malloc(sizeof(struct overlapped))) == NULL) {
 - log_printf(LOG_ERR, malloc() failed in %s: %m, __func__);
 + if ((lap = calloc(1, sizeof(struct overlapped))) == NULL) {
 + log_printf(LOG_ERR, calloc() failed in %s: %m, __func__);
   goto fail;
   }
 - memset(lap, 0, sizeof(struct overlapped));
   lap-context = context;
   lap-response_fn = response_fn;
   lap-socket = -1;
 @@ -534,13 +533,7 @@ fail:
  radius_req_setting *
  radius_req_setting_create(void)
  {
 - 

[PATCH 7] npppd: malloc/memset = calloc

2014-05-26 Thread Benjamin Baier
and a big one.

Index: common/bytebuf.c
===
RCS file: /cvs/src/usr.sbin/npppd/common/bytebuf.c,v
retrieving revision 1.5
diff -u -p -r1.5 bytebuf.c
--- common/bytebuf.c8 May 2012 13:15:11 -   1.5
+++ common/bytebuf.c26 May 2014 20:16:32 -
@@ -96,15 +96,12 @@ bytebuffer_create(size_t capacity)
 {
bytebuffer *_this = NULL;
 
-   if ((_this = malloc(sizeof(bytebuffer))) == NULL)
+   if ((_this = calloc(1, sizeof(bytebuffer))) == NULL)
return NULL;
 
-   memset(_this, 0, sizeof(bytebuffer));
-
if (capacity  0) {
-   if ((_this-data = malloc(capacity)) == NULL)
+   if ((_this-data = calloc(1, capacity)) == NULL)
goto fail;
-   memset(_this-data, 0, capacity);
_this-capacity = capacity;
} else
_this-capacity = 0;

Index: npppd/npppd_auth.c
===
RCS file: /cvs/src/usr.sbin/npppd/npppd/npppd_auth.c,v
retrieving revision 1.13
diff -u -p -r1.13 npppd_auth.c
--- npppd/npppd_auth.c  22 Mar 2014 04:23:17 -  1.13
+++ npppd/npppd_auth.c  26 May 2014 20:16:32 -
@@ -73,8 +73,7 @@ npppd_auth_create(int auth_type, const c
 
switch (auth_type) {
case NPPPD_AUTH_TYPE_LOCAL:
-   if ((base = malloc(sizeof(npppd_auth_local))) != NULL) {
-   memset(base, 0, sizeof(npppd_auth_local));
+   if ((base = calloc(1, sizeof(npppd_auth_local))) != NULL) {
base-type = NPPPD_AUTH_TYPE_LOCAL;
base-strip_nt_domain = 1;
base-strip_atmark_realm = 0;
@@ -87,9 +86,8 @@ npppd_auth_create(int auth_type, const c
 
 #ifdef USE_NPPPD_RADIUS
case NPPPD_AUTH_TYPE_RADIUS:
-   if ((base = malloc(sizeof(npppd_auth_radius))) != NULL) {
+   if ((base = calloc(1, sizeof(npppd_auth_radius))) != NULL) {
npppd_auth_radius *_this = (npppd_auth_radius *)base;
-   memset(base, 0, sizeof(npppd_auth_radius));
base-type = NPPPD_AUTH_TYPE_RADIUS;
base-strip_nt_domain = 0;
strlcpy(base-name, name, sizeof(base-name));

Index: npppd/npppd_ctl.c
===
RCS file: /cvs/src/usr.sbin/npppd/npppd/npppd_ctl.c,v
retrieving revision 1.11
diff -u -p -r1.11 npppd_ctl.c
--- npppd/npppd_ctl.c   22 Mar 2014 04:30:31 -  1.11
+++ npppd/npppd_ctl.c   26 May 2014 20:16:32 -
@@ -71,9 +71,8 @@ npppd_ctl_create(npppd *_this)
 {
struct npppd_ctl *ctl;
 
-   if ((ctl = malloc(sizeof(struct npppd_ctl))) == NULL)
+   if ((ctl = calloc(1, sizeof(struct npppd_ctl))) == NULL)
return (NULL);
-   memset(ctl, 0, sizeof(struct npppd_ctl));
ctl-npppd = _this;
TAILQ_INIT(ctl-stopped_ppps);
 
Index: npppd/ppp.c
===
RCS file: /cvs/src/usr.sbin/npppd/npppd/ppp.c,v
retrieving revision 1.20
diff -u -p -r1.20 ppp.c
--- npppd/ppp.c 22 Mar 2014 04:32:39 -  1.20
+++ npppd/ppp.c 26 May 2014 20:16:32 -
@@ -109,11 +109,10 @@ ppp_create()
 {
npppd_ppp *_this;
 
-   if ((_this = malloc(sizeof(npppd_ppp))) == NULL) {
-   log_printf(LOG_ERR, malloc() failed in %s(): %m, __func__ );
+   if ((_this = calloc(1, sizeof(npppd_ppp))) == NULL) {
+   log_printf(LOG_ERR, calloc() failed in %s(): %m, __func__ );
return NULL;
}
-   memset(_this, 0, sizeof(npppd_ppp));
 
_this-snp.snp_family = AF_INET;
_this-snp.snp_len = sizeof(_this-snp);

Index: npppd/radius_req.c
===
RCS file: /cvs/src/usr.sbin/npppd/npppd/radius_req.c,v
retrieving revision 1.7
diff -u -p -r1.7 radius_req.c
--- npppd/radius_req.c  22 Mar 2014 04:25:00 -  1.7
+++ npppd/radius_req.c  26 May 2014 20:16:33 -
@@ -275,11 +275,10 @@ radius_prepare(radius_req_setting *setti
 
if (setting-server[setting-curr_server].enabled == 0)
return 1;
-   if ((lap = malloc(sizeof(struct overlapped))) == NULL) {
-   log_printf(LOG_ERR, malloc() failed in %s: %m, __func__);
+   if ((lap = calloc(1, sizeof(struct overlapped))) == NULL) {
+   log_printf(LOG_ERR, calloc() failed in %s: %m, __func__);
goto fail;
}
-   memset(lap, 0, sizeof(struct overlapped));
lap-context = context;
lap-response_fn = response_fn;
lap-socket = -1;
@@ -534,13 +533,7 @@ fail:
 radius_req_setting *
 radius_req_setting_create(void)
 {
-   radius_req_setting *setting;
-
-   if ((setting = malloc(sizeof(radius_req_setting))) == NULL)
-   return NULL;
-