[Git][NTPsec/ntpsec][master] 2 commits: replace several emaloc()/memset() pairs with emalloc_zero().

Gary E. Miller gitlab at mg.gitlab.com
Thu May 25 21:04:12 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
0daa9387 by Gary E. Miller at 2017-05-25T13:58:04-07:00
replace several emaloc()/memset() pairs with emalloc_zero().

- - - - -
24b6ec56 by Gary E. Miller at 2017-05-25T14:03:04-07:00
generic: replace an emalloc()/memset() with emalloc_zero().

Also remove a test that can never fail.

- - - - -


5 changed files:

- ntpd/refclock_generic.c
- ntpd/refclock_jjy.c
- ntpd/refclock_oncore.c
- ntpd/refclock_pps.c
- ntpd/refclock_zyfer.c


Changes:

=====================================
ntpd/refclock_generic.c
=====================================
--- a/ntpd/refclock_generic.c
+++ b/ntpd/refclock_generic.c
@@ -4765,13 +4765,9 @@ trimbletsip_init(
 	{
 		trimble_t *t;
 
-		t = (trimble_t *)(parse->localdata = emalloc(sizeof(trimble_t)));
-
-		if (t)
-		{
-			memset((char *)t, 0, sizeof(trimble_t));
-			t->last_msg = current_time;
-		}
+		t = emalloc_zero(sizeof(trimble_t));
+		parse->localdata = t;
+		t->last_msg = current_time;
 	}
 
 	parse->peer->procptr->action     = trimble_check;


=====================================
ntpd/refclock_jjy.c
=====================================
--- a/ntpd/refclock_jjy.c
+++ b/ntpd/refclock_jjy.c
@@ -419,12 +419,11 @@ jjy_start ( int unit, struct peer *peer )
 #endif
 
 	/* Allocate memory for the unit structure */
-	up = emalloc( sizeof(*up) ) ;
+	up = emalloc_zero( sizeof(*up) ) ;
 	if ( up == NULL ) {
 		msyslog ( LOG_ERR, "refclock_jjy.c : jjy_start : emalloc" ) ;
 		return false ;
 	}
-	memset ( up, 0, sizeof(*up) ) ;
 
 	up->bInitError = false ;
 	up->iProcessState = JJY_PROCESS_STATE_IDLE ;


=====================================
ntpd/refclock_oncore.c
=====================================
--- a/ntpd/refclock_oncore.c
+++ b/ntpd/refclock_oncore.c
@@ -593,8 +593,7 @@ oncore_start(
 
 	/* create instance structure for this unit */
 
-	instance = emalloc(sizeof(*instance));
-	memset(instance, 0, sizeof(*instance));
+	instance = emalloc_zero(sizeof(*instance));
 
 	/* initialize miscellaneous variables */
 
@@ -985,8 +984,7 @@ oncore_init_shmem(
 	}
 	shmem_length = n + 2;
 
-	buf = emalloc(shmem_length);
-	memset(buf, 0, shmem_length);
+	buf = emalloc_zero(shmem_length);
 
 	/* next build the new SHMEM buffer in memory */
 


=====================================
ntpd/refclock_pps.c
=====================================
--- a/ntpd/refclock_pps.c
+++ b/ntpd/refclock_pps.c
@@ -134,8 +134,7 @@ pps_start(
 	pp->stratum = STRATUM_UNSPEC;
 	memcpy((char *)&pp->refid, REFID, REFIDLEN);
 	peer->sstclktype = CTL_SST_TS_ATOM;
-	up = emalloc(sizeof(struct ppsunit));
-	memset(up, 0, sizeof(struct ppsunit));
+	up = emalloc_zero(sizeof(struct ppsunit));
 	pp->unitptr = up;
 
 	/*


=====================================
ntpd/refclock_zyfer.c
=====================================
--- a/ntpd/refclock_zyfer.c
+++ b/ntpd/refclock_zyfer.c
@@ -138,8 +138,7 @@ zyfer_start(
 	/*
 	 * Allocate and initialize unit structure
 	 */
-	up = emalloc(sizeof(struct zyferunit));
-	memset(up, 0, sizeof(struct zyferunit));
+	up = emalloc_zero(sizeof(struct zyferunit));
 	pp = peer->procptr;
 	pp->io.clock_recv = zyfer_receive;
 	pp->io.srcclock = peer;



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/ff1d94c030898378b82e1fec7c119259e9b1e765...24b6ec56ccdd626c2c7187775fb699b594db4c6e

---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/ff1d94c030898378b82e1fec7c119259e9b1e765...24b6ec56ccdd626c2c7187775fb699b594db4c6e
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170525/cc08f178/attachment.html>


More information about the vc mailing list