[Git][NTPsec/ntpsec][master] 6 commits: systime: Fix comparing a double to zero.
Gary E. Miller
gitlab at mg.gitlab.com
Sat Apr 22 23:34:53 UTC 2017
Gary E. Miller pushed to branch master at NTPsec / ntpsec
Commits:
7b85303b by Gary E. Miller at 2017-04-22T14:40:55-07:00
systime: Fix comparing a double to zero.
- - - - -
124f5a54 by Gary E. Miller at 2017-04-22T14:45:57-07:00
ntp_loopfilter: fix 4 comparisons of double to zero.
- - - - -
3d1ce9b9 by Gary E. Miller at 2017-04-22T14:49:49-07:00
ntp_conrol: fix comparing double to zero
- - - - -
253d0b6a by Gary E. Miller at 2017-04-22T14:50:04-07:00
ntp_loopfilter: fix comparing double to zero.
- - - - -
00ecbb09 by Gary E. Miller at 2017-04-22T14:52:13-07:00
ntp_proto: fix comparing a double to zero.
- - - - -
3fa67c08 by Gary E. Miller at 2017-04-22T14:58:57-07:00
ntp_scanner: fix a double compared to zero. Add fixme.
Return of atof() tested for errno, but atof() never sets errno.
- - - - -
5 changed files:
- libntp/systime.c
- ntpd/ntp_control.c
- ntpd/ntp_loopfilter.c
- ntpd/ntp_proto.c
- ntpd/ntp_scanner.c
Changes:
=====================================
libntp/systime.c
=====================================
--- a/libntp/systime.c
+++ b/libntp/systime.c
@@ -250,7 +250,7 @@ adj_systime(
* EVNT_NSET adjtime() can be aborted by a tiny adjtime()
* triggered by sys_residual.
*/
- if (0. == now)
+ if ( D_ISZERO_NS(now))
return true;
/*
=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -2180,7 +2180,7 @@ ctl_putpeer(
break;
case CP_BIAS:
- if (p->bias != 0.)
+ if ( !D_ISZERO_NS(p->bias) )
ctl_putdbl(peer_var[id].text, p->bias * MS_PER_S);
break;
=====================================
ntpd/ntp_loopfilter.c
=====================================
--- a/ntpd/ntp_loopfilter.c
+++ b/ntpd/ntp_loopfilter.c
@@ -1335,7 +1335,7 @@ loop_config(
case LOOP_MAX: /* step threshold (step) */
clock_max_fwd = clock_max_back = freq;
- if (freq == 0 || freq > 0.5)
+ if ( D_ISZERO_NS(freq) || freq > 0.5)
select_loop(false);
break;
@@ -1346,15 +1346,15 @@ loop_config(
* limits are massive. This assumes the reason to stop
* using it is that it's pointless, not that it goes wrong.
*/
- if ( (clock_max_back == 0 || clock_max_back > 0.5)
- || (clock_max_fwd == 0 || clock_max_fwd > 0.5))
+ if ( D_ISZERO_NS(clock_max_back) || (clock_max_back > 0.5)
+ || D_ISZERO_NS(clock_max_fwd) || (clock_max_fwd > 0.5))
select_loop(false);
break;
case LOOP_MAX_FWD: /* step threshold (step) */
clock_max_fwd = freq;
- if ( (clock_max_back == 0 || clock_max_back > 0.5)
- || (clock_max_fwd == 0 || clock_max_fwd > 0.5))
+ if ( D_ISZERO_NS(clock_max_back) || (clock_max_back > 0.5)
+ || D_ISZERO_NS(clock_max_fwd) || (clock_max_fwd > 0.5))
select_loop(false);
break;
=====================================
ntpd/ntp_proto.c
=====================================
--- a/ntpd/ntp_proto.c
+++ b/ntpd/ntp_proto.c
@@ -1983,7 +1983,7 @@ clock_select(void)
sys_clockhop = 0;
} else if ((x = fabs(typesystem->offset -
osys_peer->offset)) < sys_mindisp) {
- if (sys_clockhop == 0)
+ if ( D_ISZERO_NS(sys_clockhop) )
sys_clockhop = sys_mindisp;
else
sys_clockhop *= .5;
=====================================
ntpd/ntp_scanner.c
=====================================
--- a/ntpd/ntp_scanner.c
+++ b/ntpd/ntp_scanner.c
@@ -28,6 +28,7 @@
#include "ntp_config.h"
#include "ntp_scanner.h"
#include "ntp_parser.tab.h"
+#include "timespecops.h" /* for D_ISZERO_NS() */
/* ntp_keyword.h declares finite state machine and token text */
#include "ntp_keyword.h"
@@ -933,14 +934,16 @@ yylex(void)
} else if (is_double(yytext)) {
yylval_was_set = true;
errno = 0;
- if ((yylval.Double = atof(yytext)) == 0 && errno == ERANGE) {
- msyslog(LOG_ERR,
- "Double too large to represent: %s",
- yytext);
- exit(1);
+ yylval.Double = atof(yytext);
+ if ( D_ISZERO_NS(yylval.Double) && errno == ERANGE) {
+ /* FIXME, POSIX says atof() never returns errors */
+ msyslog(LOG_ERR,
+ "Double too large to represent: %s",
+ yytext);
+ exit(1);
} else {
- token = T_Double;
- goto normal_return;
+ token = T_Double;
+ goto normal_return;
}
} else {
/* Default: Everything is a string */
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/4162ff742344a8a5b0579d66369c8d6e48f4ee96...3fa67c084e9972496a6af7092181f87e7db5b4fa
---
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/4162ff742344a8a5b0579d66369c8d6e48f4ee96...3fa67c084e9972496a6af7092181f87e7db5b4fa
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/20170422/353791e0/attachment.html>
More information about the vc
mailing list