[Git][NTPsec/ntpsec][master] Fix Coverty complaint about returning pointer to stack.

Hal Murray gitlab at mg.gitlab.com
Wed Jan 20 05:37:21 UTC 2016


Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
e6c6ac9b by Hal Murray at 2016-01-19T21:35:40-08:00
Fix Coverty complaint about returning pointer to stack.

Drop ntp2unix_tm - not used.

- - - - -


2 changed files:

- include/ntp_fp.h
- libntp/prettydate.c


Changes:

=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -358,8 +358,6 @@ extern	void	get_systime	(l_fp *);
 extern	bool	step_systime	(double, int (*settime)(struct timespec *));
 extern	bool	adj_systime	(double, int (*adjtime)(const struct timeval *, struct timeval *));
 
-extern	struct tm * ntp2unix_tm (uint32_t ntp, int local);
-
 #define	lfptoa(fpv, ndec)	mfptoa((fpv)->l_ui, (fpv)->l_uf, (ndec))
 #define	lfptoms(fpv, ndec)	mfptoms((fpv)->l_ui, (fpv)->l_uf, (ndec))
 


=====================================
libntp/prettydate.c
=====================================
--- a/libntp/prettydate.c
+++ b/libntp/prettydate.c
@@ -53,10 +53,11 @@ static char *common_prettydate(l_fp *, bool);
 
 static struct tm *
 get_struct_tm(
-	const vint64 *stamp,
-	int	      local)
+	const	vint64 *stamp,
+	int	local,
+	struct	tm *tmbuf)
 {
-	struct tm  tmbuf, *tm = NULL;
+	struct tm *tm;
 	int32_t	   folds = 0;
 	time_t	   ts;
 
@@ -93,7 +94,7 @@ get_struct_tm(
 	 * versions of 'gmtime_r()' and 'localtime_r()' will bark on time
 	 * stamps < 0.
 	 */
-	while ((tm = (*(local ? localtime_r : gmtime_r))(&ts, &tmbuf)) == NULL)
+	while ((tm = (*(local ? localtime_r : gmtime_r))(&ts, tmbuf)) == NULL)
 		if (ts < 0) {
 			if (--folds < MINFOLD)
 				return NULL;
@@ -126,7 +127,7 @@ common_prettydate(
 	    "%08lx.%08lx %04d-%02d-%02dT%02d:%02d:%02d.%03u";
 
 	char	    *bp;
-	struct tm   *tm;
+	struct tm   *tm, tmbuf;
 	u_int	     msec;
 	uint32_t	     ntps;
 	vint64	     sec;
@@ -141,7 +142,7 @@ common_prettydate(
 		ntps++;
 	}
 	sec = ntpcal_ntp_to_time(ntps, NULL);
-	tm  = get_struct_tm(&sec, local);
+	tm  = get_struct_tm(&sec, local, &tmbuf);
 	if (!tm) {
 		/*
 		 * get a replacement, but always in UTC, using
@@ -192,14 +193,3 @@ gmprettydate(
 	return common_prettydate(ts, false);
 }
 
-
-struct tm *
-ntp2unix_tm(
-	uint32_t ntp, int local
-	)
-{
-	vint64 vl;
-	vl = ntpcal_ntp_to_time(ntp, NULL);
-	return get_struct_tm(&vl, local);
-}
-	



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/e6c6ac9b00bf209b0b7b1e70b2d32405315712ac
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160120/46b18555/attachment.html>


More information about the vc mailing list