[ntp:bk-ntp-dev-send] BitKeeper diffs
Harlan Stenn
stenn at whimsy.udel.edu
Wed Feb 3 08:34:24 UTC 2010
#### ChangeSet ####
2010-02-03 04:58:33+00:00, davehart at shiny.ad.hartbrothers.com
[Bug 1455] ntpd does not try /etc/ntp.audio as documented.
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
==== ChangeLog ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +4 -0
[Bug 1455] ntpd does not try /etc/ntp.audio as documented.
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.496.26.33/ChangeLog 2010-02-02 03:09:04 -05:00
+++ 1.496.26.34/ChangeLog 2010-02-02 23:58:29 -05:00
@@ -1,8 +1,12 @@
---
+* [Bug 1455] ntpd does not try /etc/ntp.audio as documented.
* [Bug 1467] Fix bogus rebuild of sntp/sntp.html
* [Bug 1470] "make distdir" in $srcdir builds keyword-gen, libntp.a.
* [Bug 1473] "make distcheck" before build can't make sntp/version.m4.
+* Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
+* Fix widely cut-n-pasted bug in refclock shutdown after failed start.
+* Remove some dead code checking for emalloc() returning NULL.
---
(4.2.6p1-RC3) 2010/01/24 Released by Harlan Stenn <stenn at ntp.org>
==== lib/isc/win32/interfaceiter.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +11 -8
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.16/lib/isc/win32/interfaceiter.c 2010-01-01 23:41:53 -05:00
+++ 1.17/lib/isc/win32/interfaceiter.c 2010-02-02 23:58:29 -05:00
@@ -373,14 +373,15 @@ internal_current(isc_interfaceiter_t *it
if ((flags & IFF_POINTTOPOINT) != 0) {
iter->current.flags |= INTERFACE_F_POINTTOPOINT;
- sprintf(iter->current.name, "PPP %d", iter->numIF);
+ snprintf(iter->current.name, sizeof(iter->current.name),
+ "PPP %d", iter->numIF);
ifNamed = TRUE;
}
if ((flags & IFF_LOOPBACK) != 0) {
iter->current.flags |= INTERFACE_F_LOOPBACK;
- sprintf(iter->current.name, "v4loop %d",
- iter->numIF);
+ snprintf(iter->current.name, sizeof(iter->current.name),
+ "v4loop %d", iter->numIF);
ifNamed = TRUE;
}
@@ -408,7 +409,7 @@ internal_current(isc_interfaceiter_t *it
&iter->current.netmask);
if (ifNamed == FALSE)
- sprintf(iter->current.name,
+ snprintf(iter->current.name, sizeof(iter->current.name),
"IPv4 %d", iter->numIF);
return (ISC_R_SUCCESS);
@@ -468,14 +469,16 @@ internal_current6(isc_interfaceiter_t *i
sizeof(iter->current.address.type.in6))) {
iter->current.flags |= INTERFACE_F_LOOPBACK;
- sprintf(iter->current.name, "v6loop %d",
- iter->buf6->iAddressCount - iter->pos6);
+ snprintf(iter->current.name, sizeof(iter->current.name),
+ "v6loop %d",
+ iter->buf6->iAddressCount - iter->pos6);
ifNamed = TRUE;
}
if (ifNamed == FALSE)
- sprintf(iter->current.name, "IPv6 %d",
- iter->buf6->iAddressCount - iter->pos6);
+ snprintf(iter->current.name, sizeof(iter->current.name),
+ "IPv6 %d",
+ iter->buf6->iAddressCount - iter->pos6);
memset(iter->current.netmask.type.in6.s6_addr, 0xff,
sizeof(iter->current.netmask.type.in6.s6_addr));
==== libntp/audio.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +8 -5
[Bug 1455] ntpd does not try /etc/ntp.audio as documented.
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.26/libntp/audio.c 2007-01-25 19:19:16 -05:00
+++ 1.27/libntp/audio.c 2010-02-02 23:58:29 -05:00
@@ -121,15 +121,18 @@ audio_config_read(
FILE *fd;
char device[20], line[100], ab[100];
- sprintf(device, "%s%d", INIT_FILE, unit);
+ snprintf(device, sizeof(device), "%s%d", INIT_FILE, unit);
if ((fd = fopen(device, "r")) == NULL) {
printf("audio_config_read: <%s> NO\n", device);
- sprintf(device, "%s.%d", INIT_FILE, unit);
+ snprintf(device, sizeof(device), "%s.%d", INIT_FILE,
+ unit);
if ((fd = fopen(device, "r")) == NULL) {
printf("audio_config_read: <%s> NO\n", device);
- sprintf(device, "%s.%d", INIT_FILE, unit);
+ snprintf(device, sizeof(device), "%s",
+ INIT_FILE);
if ((fd = fopen(device, "r")) == NULL) {
- printf("audio_config_read: <%s> NO\n", device);
+ printf("audio_config_read: <%s> NO\n",
+ device);
return;
}
}
@@ -233,7 +236,7 @@ audio_init(
;
#ifdef PCM_STYLE_SOUND
- (void)sprintf(actl_dev, ACTL_DEV, unit);
+ snprintf(actl_dev, sizeof(actl_dev), ACTL_DEV, unit);
audio_config_read(unit, &actl, &dname);
/* If we have values for cf_c_dev or cf_i_dev, use them. */
==== libntp/findconfig.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +3 -3
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.2/libntp/findconfig.c 2001-10-08 21:18:10 -04:00
+++ 1.3/libntp/findconfig.c 2010-02-02 23:58:29 -05:00
@@ -28,7 +28,7 @@ FindConfig(
/* First choice is my hostname */
if (gethostname(hostname, BUFSIZ) >= 0) {
- (void) sprintf(result, "%s/%s", base, hostname);
+ snprintf(result, sizeof(result), "%s/%s", base, hostname);
if (stat(result, &sbuf) == 0) {
goto outahere;
} else {
@@ -39,13 +39,13 @@ FindConfig(
cp = unamebuf.machine + 5;
else
cp = unamebuf.machine;
- (void) sprintf(result, "%s/default.%s", base, cp);
+ snprintf(result, sizeof(result), "%s/default.%s", base, cp);
if (stat(result, &sbuf) == 0) {
goto outahere;
} else {
/* Last choice is just default */
- (void) sprintf(result, "%s/default", base);
+ snprintf(result, sizeof(result), "%s/default", base);
if (stat(result, &sbuf) == 0) {
goto outahere;
} else {
==== libntp/humandate.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +7 -6
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.7/libntp/humandate.c 2009-04-02 22:48:52 -05:00
+++ 1.7.1.1/libntp/humandate.c 2010-02-02 23:58:29 -05:00
@@ -15,19 +15,20 @@ extern const char *months[]; /* prettyda
char *
humanlogtime(void)
{
- char *bp;
- time_t cursec = time((time_t *) 0);
- struct tm *tm;
+ char * bp;
+ time_t cursec;
+ struct tm * tm;
+ cursec = time(NULL);
tm = localtime(&cursec);
if (!tm)
return "-- --- --:--:--";
LIB_GETBUF(bp);
- (void) sprintf(bp, "%2d %s %02d:%02d:%02d",
- tm->tm_mday, months[tm->tm_mon],
- tm->tm_hour, tm->tm_min, tm->tm_sec);
+ snprintf(bp, LIB_BUFLENGTH, "%2d %s %02d:%02d:%02d",
+ tm->tm_mday, months[tm->tm_mon],
+ tm->tm_hour, tm->tm_min, tm->tm_sec);
return bp;
}
==== libntp/modetoa.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +2 -2
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.2/libntp/modetoa.c 2001-10-08 21:18:11 -04:00
+++ 1.2.1.1/libntp/modetoa.c 2010-02-02 23:58:29 -05:00
@@ -24,9 +24,9 @@ modetoa(
"bclient",
};
- if (mode < 0 || mode >= (sizeof modestrings)/sizeof(char *)) {
+ if (mode < 0 || mode >= COUNTOF(modestrings)) {
LIB_GETBUF(bp);
- (void)sprintf(bp, "mode#%d", mode);
+ snprintf(bp, LIB_BUFLENGTH, "mode#%d", mode);
return bp;
}
==== libntp/prettydate.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +11 -10
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.12/libntp/prettydate.c 2009-04-28 02:59:35 -04:00
+++ 1.12.1.1/libntp/prettydate.c 2010-02-02 23:58:29 -05:00
@@ -170,16 +170,17 @@ common_prettydate(
msec = ts->l_uf / 4294967; /* fract / (2 ** 32 / 1000) */
tm = ntp2unix_tm(sec, local);
- if (!tm) {
- (void) sprintf(bp, "%08lx.%08lx --- --- -- ---- --:--:--",
- (u_long)ts->l_ui, (u_long)ts->l_uf);
- }
- else {
- (void) sprintf(bp, "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03lu",
- (u_long)ts->l_ui, (u_long)ts->l_uf, days[tm->tm_wday],
- months[tm->tm_mon], tm->tm_mday, 1900 + tm->tm_year,
- tm->tm_hour,tm->tm_min, tm->tm_sec, msec);
- }
+ if (!tm)
+ snprintf(bp, LIB_BUFLENGTH,
+ "%08lx.%08lx --- --- -- ---- --:--:--",
+ (u_long)ts->l_ui, (u_long)ts->l_uf);
+ else
+ snprintf(bp, LIB_BUFLENGTH,
+ "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03lu",
+ (u_long)ts->l_ui, (u_long)ts->l_uf,
+ days[tm->tm_wday], months[tm->tm_mon],
+ tm->tm_mday, 1900 + tm->tm_year, tm->tm_hour,
+ tm->tm_min, tm->tm_sec, msec);
return bp;
}
==== libntp/uglydate.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +5 -3
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.3/libntp/uglydate.c 2001-10-08 21:18:13 -04:00
+++ 1.3.1.1/libntp/uglydate.c 2010-02-02 23:58:29 -05:00
@@ -41,8 +41,10 @@ uglydate(
while (year >= 100)
year -= 100;
}
- (void) sprintf(bp, "%17s %02d:%03d:%02d:%02d:%02d.%03ld",
- timep, year, tm->tm_yday, tm->tm_hour, tm->tm_min,
- tm->tm_sec, msec);
+ snprintf(bp, LIB_BUFLENGTH,
+ "%17s %02d:%03d:%02d:%02d:%02d.%03ld", timep, year,
+ tm->tm_yday, tm->tm_hour, tm->tm_min, tm->tm_sec,
+ msec);
+
return bp;
}
==== libntp/uinttoa.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +1 -1
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.2/libntp/uinttoa.c 2001-10-08 21:18:13 -04:00
+++ 1.2.1.1/libntp/uinttoa.c 2010-02-02 23:58:29 -05:00
@@ -14,7 +14,7 @@ uinttoa(
register char *buf;
LIB_GETBUF(buf);
+ snprintf(buf, LIB_BUFLENGTH, "%lu", uval);
- (void) sprintf(buf, "%lu", (u_long)uval);
return buf;
}
==== ntpd/ntp_control.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +35 -32
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.129/ntpd/ntp_control.c 2009-11-07 17:46:40 -05:00
+++ 1.129.1.1/ntpd/ntp_control.c 2010-02-02 23:58:29 -05:00
@@ -1080,9 +1080,9 @@ ctl_putdbl(
while (*cq != '\0')
*cp++ = *cq++;
*cp++ = '=';
- (void)sprintf(cp, "%.3f", ts);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "%.3f", ts);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)(cp - buffer), 0);
}
@@ -1105,9 +1105,9 @@ ctl_putuint(
*cp++ = *cq++;
*cp++ = '=';
- (void) sprintf(cp, "%lu", uval);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "%lu", uval);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)( cp - buffer ), 0);
}
@@ -1134,13 +1134,13 @@ ctl_putfs(
*cp++ = '=';
fstamp = uval - JAN_1970;
tm = gmtime(&fstamp);
- if (tm == NULL)
+ if (NULL == tm)
return;
-
- sprintf(cp, "%04d%02d%02d%02d%02d", tm->tm_year + 1900,
- tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer),
+ "%04d%02d%02d%02d%02d", tm->tm_year + 1900,
+ tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)( cp - buffer ), 0);
}
@@ -1165,9 +1165,9 @@ ctl_puthex(
*cp++ = *cq++;
*cp++ = '=';
- (void) sprintf(cp, "0x%lx", uval);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "0x%lx", uval);
+ cp += strlen(cp);
ctl_putdata(buffer,(unsigned)( cp - buffer ), 0);
}
@@ -1191,9 +1191,9 @@ ctl_putint(
*cp++ = *cq++;
*cp++ = '=';
- (void) sprintf(cp, "%ld", ival);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "%ld", ival);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)( cp - buffer ), 0);
}
@@ -1217,10 +1217,10 @@ ctl_putts(
*cp++ = *cq++;
*cp++ = '=';
- (void) sprintf(cp, "0x%08lx.%08lx", ts->l_ui & 0xffffffffUL,
- ts->l_uf & 0xffffffffUL);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "0x%08lx.%08lx",
+ ts->l_ui & 0xffffffffUL, ts->l_uf & 0xffffffffUL);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)( cp - buffer ), 0);
}
@@ -1245,12 +1245,13 @@ ctl_putadr(
*cp++ = *cq++;
*cp++ = '=';
- if (addr == NULL)
+ if (NULL == addr)
cq = numtoa(addr32);
else
cq = stoa(addr);
- while (*cq != '\0')
- *cp++ = *cq++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "%s", cq);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)(cp - buffer), 0);
}
@@ -1273,9 +1274,9 @@ ctl_putid(
*cp++ = *cq++;
*cp++ = '=';
- cq = id;
- while (*cq != '\0' && (cq - id) < 4)
- *cp++ = *cq++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer), "%s", id);
+ cp += strlen(cp);
ctl_putdata(buffer, (unsigned)( cp - buffer ), 0);
}
@@ -1303,9 +1304,10 @@ ctl_putarray(
if (i == 0)
i = NTP_SHIFT;
i--;
- (void)sprintf(cp, " %.2f", arr[i] * 1e3);
- while (*cp != '\0')
- cp++;
+ NTP_INSIST((cp - buffer) < sizeof(buffer));
+ snprintf(cp, sizeof(buffer) - (cp - buffer),
+ " %.2f", arr[i] * 1e3);
+ cp += strlen(cp);
} while(i != start);
ctl_putdata(buffer, (unsigned)(cp - buffer), 0);
}
@@ -1410,7 +1412,8 @@ ctl_putsys(
ctl_putstr(sys_var[CS_SYSTEM].text, str_system,
sizeof(str_system) - 1);
#else
- sprintf(str, "%s/%s", utsnamebuf.sysname, utsnamebuf.release);
+ snprintf(str, sizeof(str), "%s/%s", utsnamebuf.sysname,
+ utsnamebuf.release);
ctl_putstr(sys_var[CS_SYSTEM].text, str, strlen(str));
#endif /* HAVE_UNAME */
break;
==== ntpd/refclock_arbiter.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +9 -9
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
--- 1.14/ntpd/refclock_arbiter.c 2007-01-03 16:40:06 -05:00
+++ 1.15/ntpd/refclock_arbiter.c 2010-02-02 23:58:29 -05:00
@@ -147,25 +147,23 @@ arb_start(
/*
* Open serial port. Use CLK line discipline, if available.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
if (!(fd = refclock_open(device, SPEED232, LDISC_CLK)))
return (0);
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct arbunit *)emalloc(sizeof(struct arbunit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct arbunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = arb_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
@@ -196,8 +194,10 @@ arb_shutdown(
pp = peer->procptr;
up = (struct arbunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
==== ntpd/refclock_arc.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +13 -7
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.21/ntpd/refclock_arc.c 2009-07-24 21:12:24 -04:00
+++ 1.22/ntpd/refclock_arc.c 2010-02-02 23:58:29 -05:00
@@ -646,7 +646,7 @@ arc_start(
/*
* Open serial port. Use CLK line discipline, if available.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
if (!(fd = refclock_open(device, SPEED, LDISC_CLK)))
return(0);
#ifdef DEBUG
@@ -690,16 +690,20 @@ arc_start(
#endif
- up = (struct arcunit *) emalloc(sizeof(struct arcunit));
- if(!up) { (void) close(fd); return(0); }
+ up = emalloc(sizeof(*up));
/* Set structure to all zeros... */
- memset((char *)up, 0, sizeof(struct arcunit));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = arc_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
- if(!io_addclock(&pp->io)) { (void) close(fd); free(up); return(0); }
+ if (!io_addclock(&pp->io)) {
+ close(fd);
+ pp->io.fd = -1;
+ free(up);
+ return(0);
+ }
pp->unitptr = (caddr_t)up;
/*
@@ -772,8 +776,10 @@ arc_shutdown(
pp = peer->procptr;
up = (struct arcunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
/*
==== ntpd/refclock_as2201.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +9 -10
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.10/ntpd/refclock_as2201.c 2007-01-03 16:40:06 -05:00
+++ 1.11/ntpd/refclock_as2201.c 2010-02-02 23:58:29 -05:00
@@ -165,26 +165,23 @@ as2201_start(
/*
* Open serial port. Use CLK line discipline, if available.
*/
- (void)sprintf(gpsdev, DEVICE, unit);
+ snprintf(gpsdev, sizeof(gpsdev), DEVICE, unit);
if (!(fd = refclock_open(gpsdev, SPEED232, LDISC_CLK)))
return (0);
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct as2201unit *)
- emalloc(sizeof(struct as2201unit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct as2201unit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = as2201_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
@@ -217,8 +214,10 @@ as2201_shutdown(
pp = peer->procptr;
up = (struct as2201unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
==== ntpd/refclock_atom.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +4 -3
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.60/ntpd/refclock_atom.c 2009-06-05 19:34:59 -04:00
+++ 1.61/ntpd/refclock_atom.c 2010-02-02 23:58:29 -05:00
@@ -140,11 +140,11 @@ atom_start(
* Open PPS device. This can be any serial or parallel port and
* not necessarily the port used for the associated radio.
*/
- sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
up->fddev = tty_open(device, O_RDWR, 0777);
if (up->fddev <= 0) {
msyslog(LOG_ERR,
- "refclock_atom: %s: %m", device);
+ "refclock_atom: %s: %m", device);
return (0);
}
@@ -199,7 +199,8 @@ atom_timer(
* That's so we can make awesome Allan deviation plots.
*/
if (pp->sloppyclockflag & CLK_FLAG4) {
- sprintf(tbuf, "%.9f", pp->filter[pp->coderecv]);
+ snprintf(tbuf, sizeof(tbuf), "%.9f",
+ pp->filter[pp->coderecv]);
record_clock_stats(&peer->srcadr, tbuf);
}
}
==== ntpd/refclock_bancomm.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +28 -21
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
--- 1.11/ntpd/refclock_bancomm.c 2009-08-08 13:30:12 -04:00
+++ 1.12/ntpd/refclock_bancomm.c 2010-02-02 23:58:29 -05:00
@@ -312,8 +312,10 @@ vme_shutdown(
vme = (struct vmeunit *)pp->unitptr;
io_closeclock(&pp->io);
pp->unitptr = NULL;
- free(vme);
- if (tfp_type == 2) bcStopPci(stfp_handle);
+ if (NULL != vme)
+ free(vme);
+ if (tfp_type == 2)
+ bcStopPci(stfp_handle);
}
@@ -368,14 +370,15 @@ vme_poll(
tadr = gmtime(&tloc);
tptr->year = (unsigned short)(tadr->tm_year + 1900);
- sprintf(pp->a_lastcode,
- "%3.3d %2.2d:%2.2d:%2.2d.%.6ld %1d",
- tptr->day,
- tptr->hr,
- tptr->mn,
- tptr->sec,
- tptr->frac,
- tptr->status);
+ snprintf(pp->a_lastcode,
+ sizeof(pp->a_lastcode),
+ "%3.3d %2.2d:%2.2d:%2.2d.%.6ld %1d",
+ tptr->day,
+ tptr->hr,
+ tptr->mn,
+ tptr->sec,
+ tptr->frac,
+ tptr->status);
pp->lencode = (u_short) strlen(pp->a_lastcode);
@@ -465,37 +468,41 @@ get_datumtime(struct vmedate *time_vme)
default: /* legacy bancomm card */
if (ioctl(fd_vme, READTIME, &vts)) {
- msyslog(LOG_ERR, "get_datumtime error: %m");
+ msyslog(LOG_ERR,
+ "get_datumtime error: %m");
return(NULL);
}
/* Get day */
- sprintf(cbuf,"%3.3x", ((vts.btfp_time[ 0 ] & 0x000f) <<8) +
- ((vts.btfp_time[ 1 ] & 0xff00) >> 8));
+ snprintf(cbuf, sizeof(cbuf), "%3.3x",
+ ((vts.btfp_time[ 0 ] & 0x000f) << 8) +
+ ((vts.btfp_time[ 1 ] & 0xff00) >> 8));
time_vme->day = (unsigned short)atoi(cbuf);
/* Get hour */
- sprintf(cbuf,"%2.2x", vts.btfp_time[ 1 ] & 0x00ff);
-
+ snprintf(cbuf, sizeof(cbuf), "%2.2x",
+ vts.btfp_time[ 1 ] & 0x00ff);
time_vme->hr = (unsigned short)atoi(cbuf);
/* Get minutes */
- sprintf(cbuf,"%2.2x", (vts.btfp_time[ 2 ] & 0xff00) >>8);
+ snprintf(cbuf, sizeof(cbuf), "%2.2x",
+ (vts.btfp_time[ 2 ] & 0xff00) >> 8);
time_vme->mn = (unsigned short)atoi(cbuf);
/* Get seconds */
- sprintf(cbuf,"%2.2x", vts.btfp_time[ 2 ] & 0x00ff);
+ snprintf(cbuf, sizeof(cbuf), "%2.2x",
+ vts.btfp_time[ 2 ] & 0x00ff);
time_vme->sec = (unsigned short)atoi(cbuf);
/* Get microseconds. Yes, we ignore the 0.1 microsecond digit so
we can use the TVTOTSF function later on...*/
- sprintf(cbuf,"%4.4x%2.2x", vts.btfp_time[ 3 ],
- vts.btfp_time[ 4 ]>>8);
-
+ snprintf(cbuf, sizeof(cbuf), "%4.4x%2.2x",
+ vts.btfp_time[ 3 ],
+ vts.btfp_time[ 4 ] >> 8);
time_vme->frac = (u_long) atoi(cbuf);
/* Get status bit */
- time_vme->status = (vts.btfp_time[0] & 0x0010) >>4;
+ time_vme->status = (vts.btfp_time[0] & 0x0010) >> 4;
break;
}
==== ntpd/refclock_chronolog.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +10 -10
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.8/ntpd/refclock_chronolog.c 2009-07-24 21:12:24 -04:00
+++ 1.9/ntpd/refclock_chronolog.c 2010-02-02 23:58:29 -05:00
@@ -104,7 +104,7 @@ chronolog_start(
* Open serial port. Don't bother with CLK line discipline, since
* it's not available.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
#ifdef DEBUG
if (debug)
printf ("starting Chronolog with device %s\n",device);
@@ -115,12 +115,8 @@ chronolog_start(
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct chronolog_unit *)
- emalloc(sizeof(struct chronolog_unit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct chronolog_unit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = chronolog_receive;
@@ -128,8 +124,10 @@ chronolog_start(
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
+ pp->unitptr = NULL;
return (0);
}
@@ -157,8 +155,10 @@ chronolog_shutdown(
pp = peer->procptr;
up = (struct chronolog_unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
==== ntpd/refclock_chu.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +44 -20
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.45/ntpd/refclock_chu.c 2009-01-17 19:25:15 -05:00
+++ 1.46/ntpd/refclock_chu.c 2010-02-02 23:58:29 -05:00
@@ -489,7 +489,7 @@ chu_start(
if (fd_audio > 0) {
fd = fd_audio;
} else {
- sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
fd = refclock_open(device, SPEED232, LDISC_RAW);
}
#else /* HAVE_AUDIO */
@@ -497,7 +497,7 @@ chu_start(
/*
* Open serial port in raw mode.
*/
- sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
fd = refclock_open(device, SPEED232, LDISC_RAW);
#endif /* HAVE_AUDIO */
if (fd < 0)
@@ -506,12 +506,8 @@ chu_start(
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct chuunit *)
- emalloc(sizeof(struct chuunit)))) {
- close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct chuunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = chu_receive;
@@ -520,7 +516,9 @@ chu_start(
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
close(fd);
+ pp->io.fd = -1;
free(up);
+ pp->unitptr = NULL;
return (0);
}
@@ -1103,6 +1101,9 @@ chu_b(
u_char code[11]; /* decoded timecode */
char tbuf[80]; /* trace buffer */
+ char * p;
+ size_t chars;
+ size_t cb;
int i;
pp = peer->procptr;
@@ -1115,10 +1116,20 @@ chu_b(
* only if the distance is 40. Note that once a valid frame has
* been found errors are ignored.
*/
- sprintf(tbuf, "chuB %04x %4.0f %2d %2d ", up->status,
- up->maxsignal, nchar, -up->burdist);
- for (i = 0; i < nchar; i++)
- sprintf(&tbuf[strlen(tbuf)], "%02x", up->cbuf[i]);
+ snprintf(tbuf, sizeof(tbuf), "chuB %04x %4.0f %2d %2d ",
+ up->status, up->maxsignal, nchar, -up->burdist);
+ cb = sizeof(tbuf);
+ p = tbuf;
+ for (i = 0; i < nchar; i++) {
+ chars = strlen(p);
+ if (cb < chars + 1) {
+ msyslog(LOG_ERR, "chu_b() fatal out buffer");
+ exit(1);
+ }
+ cb -= chars;
+ p += chars;
+ snprintf(p, cb, "%02x", up->cbuf[i]);
+ }
if (pp->sloppyclockflag & CLK_FLAG4)
record_clock_stats(&peer->srcadr, tbuf);
#ifdef DEBUG
@@ -1163,6 +1174,9 @@ chu_a(
struct chuunit *up;
char tbuf[80]; /* trace buffer */
+ char * p;
+ size_t chars;
+ size_t cb;
l_fp offset; /* timestamp offset */
int val; /* distance */
int temp;
@@ -1205,12 +1219,22 @@ chu_a(
if (temp < 2 || temp > 9 || k + 9 >= nchar || temp !=
((up->cbuf[k + 9] >> 4) & 0xf))
temp = 0;
- sprintf(tbuf, "chuA %04x %4.0f %2d %2d %2d %2d %1d ",
- up->status, up->maxsignal, nchar, up->burdist, k,
- up->syndist, temp);
- for (i = 0; i < nchar; i++)
- sprintf(&tbuf[strlen(tbuf)], "%02x",
- up->cbuf[i]);
+ snprintf(tbuf, sizeof(tbuf),
+ "chuA %04x %4.0f %2d %2d %2d %2d %1d ", up->status,
+ up->maxsignal, nchar, up->burdist, k, up->syndist,
+ temp);
+ cb = sizeof(tbuf);
+ p = tbuf;
+ for (i = 0; i < nchar; i++) {
+ chars = strlen(p);
+ if (cb < chars + 1) {
+ msyslog(LOG_ERR, "chu_a() fatal out buffer");
+ exit(1);
+ }
+ cb -= chars;
+ p += chars;
+ snprintf(p, cb, "%02x", up->cbuf[i]);
+ }
if (pp->sloppyclockflag & CLK_FLAG4)
record_clock_stats(&peer->srcadr, tbuf);
#ifdef DEBUG
@@ -1354,7 +1378,7 @@ chu_second(
} else {
pp->leap = LEAP_NOWARNING;
}
- sprintf(pp->a_lastcode,
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
"%c%1X %04d %03d %02d:%02d:%02d %c%x %+d %d %d %s %.0f %d",
synchar, qual, pp->year, pp->day, pp->hour, pp->minute,
pp->second, leapchar, up->dst, up->dut, minset, up->gain,
@@ -1565,7 +1589,7 @@ chu_newchan(
*/
rval = icom_freq(up->fd_icom, peer->ttl & 0x7f, qsy[up->chan] +
TUNE);
- sprintf(up->ident, "CHU%d", up->chan);
+ snprintf(up->ident, sizeof(up->ident), "CHU%d", up->chan);
memcpy(&pp->refid, up->ident, 4);
memcpy(&peer->refid, up->ident, 4);
if (metric == 0 && up->status & METRIC) {
==== ntpd/refclock_dumbclock.c ====
2010-02-03 04:58:29+00:00, davehart at shiny.ad.hartbrothers.com +10 -6
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.13/ntpd/refclock_dumbclock.c 2009-07-24 21:12:24 -04:00
+++ 1.14/ntpd/refclock_dumbclock.c 2010-02-02 23:58:29 -05:00
@@ -115,7 +115,7 @@ dumbclock_start(
* Open serial port. Don't bother with CLK line discipline, since
* it's not available.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
#ifdef DEBUG
if (debug)
printf ("starting Dumbclock with device %s\n",device);
@@ -127,8 +127,8 @@ dumbclock_start(
/*
* Allocate and initialize unit structure
*/
- up = (struct dumbclock_unit *)emalloc(sizeof(struct dumbclock_unit));
- memset((char *)up, 0, sizeof(struct dumbclock_unit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = dumbclock_receive;
@@ -136,8 +136,10 @@ dumbclock_start(
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
+ pp->unitptr = NULL;
return (0);
}
@@ -177,8 +179,10 @@ dumbclock_shutdown(
pp = peer->procptr;
up = (struct dumbclock_unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
==== ntpd/refclock_gpsvme.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +10 -11
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.7/ntpd/refclock_gpsvme.c 2003-11-19 05:06:43 -05:00
+++ 1.8/ntpd/refclock_gpsvme.c 2010-02-02 23:58:30 -05:00
@@ -104,13 +104,9 @@ psc_start(
return 0;
}
- if (!up) {
- msyslog(LOG_ERR, "psc_start: unit: %d, emalloc: %m", unit);
- return 0;
- }
memset(up, '\0', sizeof *up);
- sprintf(buf, DEVICE, unit); /* dev file name */
+ snprintf(buf, sizeof(buf), DEVICE, unit); /* dev file name */
fd[unit] = open(buf, O_RDONLY); /* open device file */
if (fd[unit] < 0) {
msyslog(LOG_ERR, "psc_start: unit: %d, open failed. %m", unit);
@@ -131,7 +127,7 @@ psc_start(
pp->io.fd = -1;
pp->unitptr = (caddr_t) up;
get_systime(&pp->lastrec);
- memcpy((char *)&pp->refid, REFID, 4);
+ memcpy(&pp->refid, REFID, 4);
peer->precision = PRECISION;
pp->clockdesc = DESCRIPTION;
up->unit = unit;
@@ -149,8 +145,10 @@ psc_shutdown(
struct peer *peer
)
{
- free(peer->procptr->unitptr);
- close(fd[unit]);
+ if (NULL != peer->procptr->unitptr)
+ free(peer->procptr->unitptr);
+ if (fd[unit] > 0)
+ close(fd[unit]);
}
/* psc_poll: read, decode, and record device time */
@@ -196,9 +194,10 @@ psc_poll(
pp->nsec = 1000000*BCD2INT3((tlo & 0x00FFF000) >> 12) +
BCD2INT3(tlo & 0x00000FFF);
- sprintf(pp->a_lastcode, "%3.3d %2.2d:%2.2d:%2.2d.%09ld %02x %08x %08x",
- pp->day, pp->hour, pp->minute, pp->second, pp->nsec, status, thi,
- tlo);
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
+ "%3.3d %2.2d:%2.2d:%2.2d.%09ld %02x %08x %08x", pp->day,
+ pp->hour, pp->minute, pp->second, pp->nsec, status, thi,
+ tlo);
pp->lencode = strlen(pp->a_lastcode);
/* compute the timecode timestamp */
==== ntpd/refclock_heath.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +6 -4
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
--- 1.14/ntpd/refclock_heath.c 2007-01-03 16:40:07 -05:00
+++ 1.15/ntpd/refclock_heath.c 2010-02-02 23:58:30 -05:00
@@ -221,7 +221,7 @@ heath_start(
/*
* Open serial port
*/
- sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
if (!(fd = refclock_open(device, speed[peer->ttl & 0x3],
LDISC_REMOTE)))
return (0);
@@ -231,7 +231,8 @@ heath_start(
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
return (0);
}
@@ -241,7 +242,7 @@ heath_start(
peer->precision = PRECISION;
peer->burst = NSTAGE;
pp->clockdesc = DESCRIPTION;
- memcpy((char *)&pp->refid, REFID, 4);
+ memcpy(&pp->refid, REFID, 4);
return (1);
}
@@ -258,7 +259,8 @@ heath_shutdown(
struct refclockproc *pp;
pp = peer->procptr;
- io_closeclock(&pp->io);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
}
==== ntpd/refclock_hopfpci.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +18 -26
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.10/ntpd/refclock_hopfpci.c 2003-11-29 19:09:20 -05:00
+++ 1.11/ntpd/refclock_hopfpci.c 2010-02-02 23:58:30 -05:00
@@ -124,24 +124,17 @@ hopfpci_start(
/*
* Allocate and initialize unit structure
*/
- up = (struct hopfclock_unit *) emalloc(sizeof(struct hopfclock_unit));
-
- if (!(up)) {
- msyslog(LOG_ERR, "hopfPCIClock(%d) emalloc: %m",unit);
-#ifdef DEBUG
- printf("hopfPCIClock(%d) emalloc\n",unit);
-#endif
- return (0);
- }
- memset((char *)up, 0, sizeof(struct hopfclock_unit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
#ifndef SYS_WINNT
fd = open(DEVICE,O_RDWR); /* try to open hopf clock device */
#else
- if (!OpenHopfDevice()){
- msyslog(LOG_ERR,"Start: %s unit: %d failed!",DEVICE,unit);
+ if (!OpenHopfDevice()) {
+ msyslog(LOG_ERR, "Start: %s unit: %d failed!", DEVICE, unit);
+ free(up);
return (0);
}
#endif
@@ -158,17 +151,12 @@ hopfpci_start(
/*
* Initialize miscellaneous peer variables
*/
- if (pp->unitptr!=0) {
- memcpy((char *)&pp->refid, REFID, 4);
- peer->precision = PRECISION;
- pp->clockdesc = DESCRIPTION;
- up->leap_status = 0;
- up->unit = (short) unit;
- return (1);
- }
- else {
- return 0;
- }
+ memcpy((char *)&pp->refid, REFID, 4);
+ peer->precision = PRECISION;
+ pp->clockdesc = DESCRIPTION;
+ up->leap_status = 0;
+ up->unit = (short) unit;
+ return (1);
}
@@ -187,6 +175,8 @@ hopfpci_shutdown(
#else
CloseHopfDevice();
#endif
+ if (NULL != peer->procptr->unitptr)
+ free(peer->procptr->unitptr);
}
@@ -221,9 +211,11 @@ hopfpci_poll(
else
pp->leap = LEAP_NOWARNING;
- sprintf(pp->a_lastcode,"ST: %02X T: %02d:%02d:%02d.%03ld D: %02d.%02d.%04d",
- m_time.wStatus, pp->hour, pp->minute, pp->second,
- pp->nsec / 1000000, m_time.wDay, m_time.wMonth, m_time.wYear);
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
+ "ST: %02X T: %02d:%02d:%02d.%03ld D: %02d.%02d.%04d",
+ m_time.wStatus, pp->hour, pp->minute, pp->second,
+ pp->nsec / 1000000, m_time.wDay, m_time.wMonth,
+ m_time.wYear);
pp->lencode = (u_short)strlen(pp->a_lastcode);
get_systime(&pp->lastrec);
==== ntpd/refclock_hopfser.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +13 -18
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.13/ntpd/refclock_hopfser.c 2009-06-05 19:34:59 -04:00
+++ 1.14/ntpd/refclock_hopfser.c 2010-02-02 23:58:30 -05:00
@@ -127,7 +127,7 @@ hopfserial_start (
int fd;
char gpsdev[20];
- (void) sprintf(gpsdev, DEVICE, unit);
+ snprintf(gpsdev, sizeof(gpsdev), DEVICE, unit);
/* LDISC_STD, LDISC_RAW
* Open serial port. Use CLK line discipline, if available.
@@ -146,18 +146,8 @@ hopfserial_start (
/*
* Allocate and initialize unit structure
*/
- up = (struct hopfclock_unit *) emalloc(sizeof(struct hopfclock_unit));
-
- if (!(up)) {
- msyslog(LOG_ERR, "hopfSerialClock(%d) emalloc: %m",unit);
-#ifdef DEBUG
- printf("hopfSerialClock(%d) emalloc\n",unit);
-#endif
- (void) close(fd);
- return (0);
- }
-
- memset((char *)up, 0, sizeof(struct hopfclock_unit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = hopfserial_receive;
@@ -166,10 +156,12 @@ hopfserial_start (
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
#ifdef DEBUG
- printf("hopfSerialClock(%d) io_addclock\n",unit);
+ printf("hopfSerialClock(%d) io_addclock\n", unit);
#endif
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
+ pp->unitptr = NULL;
return (0);
}
@@ -202,8 +194,11 @@ hopfserial_shutdown (
pp = peer->procptr;
up = (struct hopfclock_unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
@@ -289,7 +284,7 @@ hopfserial_receive (
/* preparation for timecode ntpq rl command ! */
#if 0
- wsprintf(pp->a_lastcode,
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
"STATUS: %1X%1X, DATE: %02d.%02d.%04d TIME: %02d:%02d:%02d",
synch,
DoW,
==== ntpd/refclock_hpgps.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +9 -10
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.9/ntpd/refclock_hpgps.c 2009-04-28 08:05:43 -04:00
+++ 1.10/ntpd/refclock_hpgps.c 2010-02-02 23:58:30 -05:00
@@ -162,7 +162,7 @@ hpgps_start(
* Open serial port. Use CLK line discipline, if available.
* Default is HP 58503A, mode arg selects HP Z3801A
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
/* mode parameter to server config line shares ttl slot */
if ((peer->ttl == 1)) {
if (!(fd = refclock_open(device, SPEED232Z,
@@ -175,19 +175,16 @@ hpgps_start(
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct hpgpsunit *)
- emalloc(sizeof(struct hpgpsunit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct hpgpsunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = hpgps_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
@@ -232,8 +229,10 @@ hpgps_shutdown(
pp = peer->procptr;
up = (struct hpgpsunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
==== ntpd/refclock_irig.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +11 -11
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.31/ntpd/refclock_irig.c 2007-06-07 01:46:42 -04:00
+++ 1.32/ntpd/refclock_irig.c 2010-02-02 23:58:30 -05:00
@@ -332,12 +332,8 @@ irig_start(
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct irigunit *)
- emalloc(sizeof(struct irigunit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct irigunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = irig_receive;
@@ -345,8 +341,10 @@ irig_start(
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void)close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
+ pp->unitptr = NULL;
return (0);
}
@@ -371,7 +369,7 @@ irig_start(
for (i = 3; i < OFFSET; i++) {
up->comp[i] = up->comp[i - 1] + step;
up->comp[OFFSET + i] = -up->comp[i];
- if (i % 16 == 0)
+ if (i % 16 == 0)
step *= 2.;
}
DTOLFP(1. / SECOND, &up->tick);
@@ -393,8 +391,10 @@ irig_shutdown(
pp = peer->procptr;
up = (struct irigunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
@@ -943,7 +943,7 @@ irig_decode(
refclock_report(peer,
CEVNT_BADTIME);
}
- sprintf(pp->a_lastcode,
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
"%02x %02d %03d %02d:%02d:%02d %4.0f %3d %6.3f %2d %6.2f %6.1f %s",
up->errflg, pp->year, pp->day,
pp->hour, pp->minute, pp->second,
==== ntpd/refclock_jjy.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +22 -22
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.17/ntpd/refclock_jjy.c 2009-05-07 03:40:03 -04:00
+++ 1.18/ntpd/refclock_jjy.c 2010-02-02 23:58:30 -05:00
@@ -250,10 +250,8 @@ jjy_start ( int unit, struct peer *peer
/*
* Open serial port
*/
- if ( ! ( pDeviceName = (char*) emalloc ( strlen(DEVICE) + 10 ) ) ) {
- return RC_START_ERROR ;
- }
- sprintf ( pDeviceName, DEVICE, unit ) ;
+ pDeviceName = emalloc ( strlen(DEVICE) + 10 );
+ snprintf ( pDeviceName, strlen(DEVICE) + 10, DEVICE, unit ) ;
/*
* peer->ttl is a mode number specified by "127.127.40.X mode N" in the ntp.conf
@@ -292,12 +290,8 @@ jjy_start ( int unit, struct peer *peer
/*
* Allocate and initialize unit structure
*/
- if ( ! ( up = (struct jjyunit *) emalloc (sizeof(struct jjyunit)) ) ) {
- close ( fd ) ;
- return RC_START_ERROR ;
- }
-
- memset ( (char*)up, 0, sizeof(struct jjyunit) ) ;
+ up = emalloc (sizeof(*up));
+ memset ( up, 0, sizeof(*up) ) ;
up->linediscipline = iDiscipline ;
/*
@@ -325,8 +319,8 @@ jjy_start ( int unit, struct peer *peer
up->unittype = UNITTYPE_ECHOKEISOKUKI_LT2000 ;
up->operationmode = 2 ; /* Mode 2 : Continuous mode */
up->lineexpect = 1 ;
- switch ( up->operationmode ) {
- case 1 :
+ switch ( up->operationmode ) {
+ case 1 :
up->charexpect[0] = 15 ; /* YYMMDDWHHMMSS<BCC1><BCC2><CR> */
break ;
case 2 :
@@ -334,11 +328,11 @@ jjy_start ( int unit, struct peer *peer
break ;
}
break ;
- case 4 :
- up->unittype = UNITTYPE_CITIZENTIC_JJY200 ;
- up->lineexpect = 1 ;
- up->charexpect[0] = 23 ; /* 'XX YY/MM/DD W HH:MM:SS<CR> */
- break ;
+ case 4 :
+ up->unittype = UNITTYPE_CITIZENTIC_JJY200 ;
+ up->lineexpect = 1 ;
+ up->charexpect[0] = 23 ; /* 'XX YY/MM/DD W HH:MM:SS<CR> */
+ break ;
default :
msyslog ( LOG_ERR, "JJY receiver [ %s mode %d ] : Unsupported mode",
ntoa(&peer->srcadr), peer->ttl ) ;
@@ -355,7 +349,9 @@ jjy_start ( int unit, struct peer *peer
pp->io.fd = fd ;
if ( ! io_addclock(&pp->io) ) {
close ( fd ) ;
- free ( (void*) up ) ;
+ pp->io.fd = -1 ;
+ free ( up ) ;
+ pp->unitptr = NULL ;
return RC_START_ERROR ;
}
@@ -384,8 +380,10 @@ jjy_shutdown ( int unit, struct peer *pe
pp = peer->procptr ;
up = (struct jjyunit *) pp->unitptr ;
- io_closeclock ( &pp->io ) ;
- free ( (void*) up ) ;
+ if ( -1 != pp->io.fd )
+ io_closeclock ( &pp->io ) ;
+ if ( NULL != up )
+ free ( up ) ;
}
@@ -546,8 +544,10 @@ jjy_receive ( struct recvbuf *rbufp )
* timecode timestamp.
*/
- sprintf ( sLogText, "%04d/%02d/%02d %02d:%02d:%02d.%1d JST",
- up->year, up->month, up->day, up->hour, up->minute, up->second, up->msecond/100 ) ;
+ snprintf ( sLogText, sizeof(sLogText),
+ "%04d/%02d/%02d %02d:%02d:%02d.%1d JST",
+ up->year, up->month, up->day,
+ up->hour, up->minute, up->second, up->msecond/100 ) ;
record_clock_stats ( &peer->srcadr, sLogText ) ;
if ( ! refclock_process ( pp ) ) {
==== ntpd/refclock_jupiter.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +6 -10
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Remove some dead code checking for emalloc() returning NULL.
--- 1.21/ntpd/refclock_jupiter.c 2007-01-03 16:40:08 -05:00
+++ 1.21.1.1/ntpd/refclock_jupiter.c 2010-02-02 23:58:30 -05:00
@@ -188,7 +188,7 @@ jupiter_start(
/*
* Open serial port
*/
- (void)sprintf(gpsdev, DEVICE, unit);
+ snprintf(gpsdev, sizeof(gpsdev), DEVICE, unit);
fd = refclock_open(gpsdev, SPEED232, LDISC_RAW);
if (fd == 0) {
jupiter_debug(peer, "jupiter_start", "open %s: %s",
@@ -197,12 +197,8 @@ jupiter_start(
}
/* Allocate unit structure */
- if ((instance = (struct instance *)
- emalloc(sizeof(struct instance))) == NULL) {
- (void) close(fd);
- return (0);
- }
- memset((char *)instance, 0, sizeof(struct instance));
+ instance = emalloc(sizeof(*instance));
+ memset(instance, 0, sizeof(*instance));
instance->peer = peer;
pp = peer->procptr;
pp->io.clock_recv = jupiter_receive;
@@ -210,7 +206,7 @@ jupiter_start(
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
free(instance);
return (0);
}
@@ -934,10 +930,10 @@ jupiter_send(struct instance *instance,
}
if ((cc = write(instance->peer->procptr->io.fd, (char *)hp, size)) < 0) {
- (void)sprintf(errstr, "write: %s", strerror(errno));
+ snprintf(errstr, sizeof(errstr), "write: %s", strerror(errno));
return (errstr);
} else if (cc != size) {
- (void)sprintf(errstr, "short write (%d != %d)", cc, size);
+ snprintf(errstr, sizeof(errstr), "short write (%d != %d)", cc, size);
return (errstr);
}
return (NULL);
==== ntpd/refclock_leitch.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +12 -3
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
call io_closeclock() on shutdown if io_addclock() succeeded.
--- 1.10/ntpd/refclock_leitch.c 2007-03-17 19:34:26 -05:00
+++ 1.11/ntpd/refclock_leitch.c 2010-02-02 23:58:30 -05:00
@@ -150,9 +150,17 @@ leitch_shutdown(
struct peer *peer
)
{
+ struct leitchunit *leitch;
+
+ if (unit >= MAXUNITS) {
+ return;
+ }
+ leitch = &leitchunits[unit];
+ if (-1 != leitch->leitchio.fd)
+ io_closeclock(&leitch->leitchio);
#ifdef DEBUG
if (debug)
- fprintf(stderr, "leitch_shutdown()\n");
+ fprintf(stderr, "leitch_shutdown()\n");
#endif
}
@@ -258,7 +266,7 @@ leitch_start(
/*
* Open serial port.
*/
- (void) sprintf(leitchdev, LEITCH232, unit);
+ snprintf(leitchdev, sizeof(leitchdev), LEITCH232, unit);
fd232 = open(leitchdev, O_RDWR, 0777);
if (fd232 == -1) {
msyslog(LOG_ERR,
@@ -267,7 +275,7 @@ leitch_start(
}
leitch = &leitchunits[unit];
- memset((char*)leitch, 0, sizeof(*leitch));
+ memset(leitch, 0, sizeof(*leitch));
#if defined(HAVE_SYSV_TTYS)
/*
@@ -387,6 +395,7 @@ leitch_start(
leitch->leitchio.datalen = 0;
leitch->leitchio.fd = fd232;
if (!io_addclock(&leitch->leitchio)) {
+ leitch->leitchio.fd = -1;
goto screwed;
}
==== ntpd/refclock_msfees.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +20 -13
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.12/ntpd/refclock_msfees.c 2006-08-08 04:11:09 -04:00
+++ 1.13/ntpd/refclock_msfees.c 2010-02-02 23:58:30 -05:00
@@ -382,11 +382,15 @@ dump_buf(
int i;
register char *ptr = buff;
- sprintf(ptr, text);
- for (i=from; i<to; i++)
- { while (*ptr) ptr++;
- if ((ptr-buff) > DUMP_BUF_SIZE) msyslog(LOG_DEBUG, "D: %s", ptr=buff);
- sprintf(ptr, " %06d", ((int)coffs[i].l_f) / 4295);
+ snprintf(buff, sizeof(buff), text);
+ for (i = from; i < to; i++) {
+ ptr += strlen(ptr);
+ if ((ptr - buff) > DUMP_BUF_SIZE) {
+ msyslog(LOG_DEBUG, "D: %s", buff);
+ ptr = buff;
+ }
+ snprintf(ptr, sizeof(buff) - (ptr - buff),
+ " %06d", ((int)coffs[i].l_f) / 4295);
}
msyslog(LOG_DEBUG, "D: %s", buff);
}
@@ -450,7 +454,7 @@ msfees_start(
/* Unit okay, attempt to open the devices. We do them both at
* once to make sure we can */
- (void) sprintf(eesdev, EES232, unit);
+ snprintf(eesdev, sizeof(eesdev), EES232, unit);
fd232 = open(eesdev, O_RDWR, 0777);
if (fd232 == -1) {
@@ -987,17 +991,20 @@ ees_receive(
/* Dump the deltas each minute */
if (dbg & DB_DUMP_DELTAS)
- { if (/*0 <= ees->second && */
- ees->second < ((sizeof deltas) / (sizeof deltas[0]))) deltas[ees->second] = delta_sfsec;
+ {
+ if (/*0 <= ees->second && */
+ ees->second < COUNTOF(deltas))
+ deltas[ees->second] = delta_sfsec;
/* Dump on second 1, as second 0 sometimes missed */
if (ees->second == 1) {
- char text[16 * ((sizeof deltas) / (sizeof deltas[0]))];
+ char text[16 * COUNTOF(deltas)];
char *cptr=text;
int i;
- for (i=0; i<((sizeof deltas) / (sizeof deltas[0])); i++) {
- sprintf(cptr, " %d.%04d",
- msec(deltas[i]), subms(deltas[i]));
- while (*cptr) cptr++;
+ for (i = 0; i < COUNTOF(deltas); i++) {
+ snprintf(cptr, sizeof(text) / COUNTOF(deltas),
+ " %d.%04d", msec(deltas[i]),
+ subms(deltas[i]));
+ cptr += strlen(cptr);
}
msyslog(LOG_ERR, "Deltas: %d.%04d<->%d.%04d: %s",
msec(EES_STEP_F - EES_STEP_F_GRACE), subms(EES_STEP_F - EES_STEP_F_GRACE),
==== ntpd/refclock_mx4200.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +11 -12
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.24/ntpd/refclock_mx4200.c 2009-04-28 02:59:37 -04:00
+++ 1.25/ntpd/refclock_mx4200.c 2010-02-02 23:58:30 -05:00
@@ -222,7 +222,7 @@ mx4200_start(
/*
* Open serial port
*/
- (void)sprintf(gpsdev, DEVICE, unit);
+ snprintf(gpsdev, sizeof(gpsdev), DEVICE, unit);
if (!(fd = refclock_open(gpsdev, SPEED232, LDISC_PPS))) {
return (0);
}
@@ -230,19 +230,16 @@ mx4200_start(
/*
* Allocate unit structure
*/
- if (!(up = (struct mx4200unit *) emalloc(sizeof(struct mx4200unit)))) {
- perror("emalloc");
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct mx4200unit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = mx4200_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
@@ -274,8 +271,10 @@ mx4200_shutdown(
pp = peer->procptr;
up = (struct mx4200unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
@@ -576,9 +575,9 @@ mx4200_ref(
}
alt = up->avg_alt;
minute = (lat - (double)(int)lat) * 60.0;
- sprintf(lats,"%02d%02.4f", (int)lat, minute);
+ snprintf(lats, sizeof(lats), "%02d%02.4f", (int)lat, minute);
minute = (lon - (double)(int)lon) * 60.0;
- sprintf(lons,"%03d%02.4f", (int)lon, minute);
+ snprintf(lons, sizeof(lons), "%03d%02.4f", (int)lon, minute);
mx4200_send(peer, "%s,%03d,,,,,%s,%c,%s,%c,%.2f,%d", pmvxg,
PMVXG_S_INITMODEA,
==== ntpd/refclock_palisade.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +11 -6
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
--- 1.31/ntpd/refclock_palisade.c 2009-09-19 12:52:44 -04:00
+++ 1.31.1.1/ntpd/refclock_palisade.c 2010-02-02 23:58:30 -05:00
@@ -273,7 +273,7 @@ palisade_start (
char gpsdev[20];
struct termios tio;
- (void) sprintf(gpsdev, DEVICE, unit);
+ snprintf(gpsdev, sizeof(gpsdev), DEVICE, unit);
/*
* Open serial port.
@@ -350,7 +350,8 @@ palisade_start (
#ifdef DEBUG
printf("Palisade(%d) io_addclock\n",unit);
#endif
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
@@ -394,8 +395,10 @@ palisade_shutdown (
struct refclockproc *pp;
pp = peer->procptr;
up = (struct palisade_unit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
@@ -920,8 +923,10 @@ palisade_receive (
* report and process
*/
- (void) sprintf(pp->a_lastcode,"%4d %03d %02d:%02d:%02d.%06ld",
- pp->year,pp->day,pp->hour,pp->minute, pp->second,pp->nsec);
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
+ "%4d %03d %02d:%02d:%02d.%06ld",
+ pp->year, pp->day,
+ pp->hour,pp->minute, pp->second, pp->nsec);
pp->lencode = 24;
if (!refclock_process(pp)) {
==== ntpd/refclock_parse.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +3 -3
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.51/ntpd/refclock_parse.c 2009-05-05 15:19:24 -04:00
+++ 1.52/ntpd/refclock_parse.c 2010-02-02 23:58:30 -05:00
@@ -1474,10 +1474,10 @@ mkreadable(
)
{
char *b = buffer;
- char *endb = (char *)0;
+ char *endb = NULL;
if (blen < 4)
- return (char *)0; /* don't bother with mini buffers */
+ return NULL; /* don't bother with mini buffers */
endb = buffer + blen - 4;
@@ -1515,7 +1515,7 @@ mkreadable(
}
else
{
- sprintf(buffer, "\\x%02x", *src++);
+ snprintf(buffer, blen, "\\x%02x", *src++);
blen -= 4;
buffer += 4;
}
==== ntpd/refclock_pcf.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +2 -2
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.9/ntpd/refclock_pcf.c 2009-07-24 21:12:24 -04:00
+++ 1.10/ntpd/refclock_pcf.c 2010-02-02 23:58:30 -05:00
@@ -72,10 +72,10 @@ pcf_start(
/*
* Open device file for reading.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
fd = open(device, O_RDONLY);
if (fd == -1) {
- (void)sprintf(device, OLDDEVICE, unit);
+ snprintf(device, sizeof(device), OLDDEVICE, unit);
fd = open(device, O_RDONLY);
}
#ifdef DEBUG
==== ntpd/refclock_pst.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +9 -9
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.9/ntpd/refclock_pst.c 2007-01-03 16:40:09 -05:00
+++ 1.10/ntpd/refclock_pst.c 2010-02-02 23:58:30 -05:00
@@ -127,25 +127,23 @@ pst_start(
/*
* Open serial port. Use CLK line discipline, if available.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
if (!(fd = refclock_open(device, SPEED232, LDISC_CLK)))
return (0);
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct pstunit *)emalloc(sizeof(struct pstunit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct pstunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = pst_receive;
pp->io.srcclock = (caddr_t)peer;
pp->io.datalen = 0;
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
- (void) close(fd);
+ close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
@@ -176,8 +174,10 @@ pst_shutdown(
pp = peer->procptr;
up = (struct pstunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
==== ntpd/refclock_shm.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +8 -6
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.20/ntpd/refclock_shm.c 2009-11-25 14:18:57 -05:00
+++ 1.21/ntpd/refclock_shm.c 2010-02-02 23:58:30 -05:00
@@ -137,8 +137,8 @@ struct shmTime *getShmTime (int unit) {
HANDLE shmid=0;
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
- sprintf (buf,"NTP%d",unit);
- if (unit>=2) { /* world access */
+ snprintf(buf, sizeof(buf), "NTP%d", unit);
+ if (unit >= 2) { /* world access */
if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) {
msyslog(LOG_ERR,"SHM InitializeSecurityDescriptor (unit %d): %m",unit);
return 0;
@@ -193,10 +193,8 @@ shm_start(
pp->io.datalen = 0;
pp->io.fd = -1;
- up = (struct shmunit *) emalloc(sizeof(*up));
- if (up == NULL)
- return (FALSE);
- memset((char *)up, 0, sizeof(*up));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp->unitptr = (caddr_t)up;
up->shm = getShmTime(unit);
@@ -233,12 +231,16 @@ shm_shutdown(
pp = peer->procptr;
up = (struct shmunit *)pp->unitptr;
+
+ if (NULL == up)
+ return;
#ifndef SYS_WINNT
/* HMS: shmdt()wants char* or const void * */
(void) shmdt ((char *)up->shm);
#else
UnmapViewOfFile (up->shm);
#endif
+ free(up);
}
==== ntpd/refclock_tpro.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +12 -14
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.10/ntpd/refclock_tpro.c 2007-11-13 16:57:28 -05:00
+++ 1.11/ntpd/refclock_tpro.c 2010-02-02 23:58:30 -05:00
@@ -77,7 +77,7 @@ tpro_start(
/*
* Open TPRO device
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
fd = open(device, O_RDONLY | O_NDELAY, 0777);
if (fd == -1) {
msyslog(LOG_ERR, "tpro_start: open of %s: %m", device);
@@ -87,11 +87,8 @@ tpro_start(
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct tprounit *) emalloc(sizeof(struct tprounit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct tprounit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = noentry;
pp->io.srcclock = (caddr_t)peer;
@@ -125,7 +122,8 @@ tpro_shutdown(
pp = peer->procptr;
up = (struct tprounit *)pp->unitptr;
io_closeclock(&pp->io);
- free(up);
+ if (NULL != up)
+ free(up);
}
@@ -170,13 +168,13 @@ tpro_poll(
* we could pad the written string appropriately and read the
* resulting value in already scaled.
*/
- sprintf(pp->a_lastcode,
- "%1x%1x%1x %1x%1x:%1x%1x:%1x%1x.%1x%1x%1x%1x%1x%1x %1x",
- tp->day100, tp->day10, tp->day1, tp->hour10, tp->hour1,
- tp->min10, tp->min1, tp->sec10, tp->sec1, tp->ms100,
- tp->ms10, tp->ms1, tp->usec100, tp->usec10, tp->usec1,
- tp->status);
- pp->lencode = strlen(pp->a_lastcode);
+ snprintf(pp->a_lastcode, sizeof(pp->a_lastcode),
+ "%1x%1x%1x %1x%1x:%1x%1x:%1x%1x.%1x%1x%1x%1x%1x%1x %1x",
+ tp->day100, tp->day10, tp->day1, tp->hour10, tp->hour1,
+ tp->min10, tp->min1, tp->sec10, tp->sec1, tp->ms100,
+ tp->ms10, tp->ms1, tp->usec100, tp->usec10, tp->usec1,
+ tp->status);
+ pp->lencode = strlen(pp->a_lastcode);
#ifdef DEBUG
if (debug)
printf("tpro: time %s timecode %d %s\n",
==== ntpd/refclock_trak.c ====
2010-02-03 04:58:30+00:00, davehart at shiny.ad.hartbrothers.com +8 -9
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
Remove some dead code checking for emalloc() returning NULL.
--- 1.8/ntpd/refclock_trak.c 2001-12-21 22:24:20 -05:00
+++ 1.9/ntpd/refclock_trak.c 2010-02-02 23:58:30 -05:00
@@ -147,7 +147,7 @@ trak_start(
* timestamp following the "*" on-time character of the
* timecode.
*/
- (void)sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
if (
#ifdef PPS
!(fd = refclock_open(device, SPEED232, LDISC_CLK))
@@ -160,12 +160,8 @@ trak_start(
/*
* Allocate and initialize unit structure
*/
- if (!(up = (struct trakunit *)
- emalloc(sizeof(struct trakunit)))) {
- (void) close(fd);
- return (0);
- }
- memset((char *)up, 0, sizeof(struct trakunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->io.clock_recv = trak_receive;
pp->io.srcclock = (caddr_t)peer;
@@ -173,6 +169,7 @@ trak_start(
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
(void) close(fd);
+ pp->io.fd = -1;
free(up);
return (0);
}
@@ -214,8 +211,10 @@ trak_shutdown(
pp = peer->procptr;
up = (struct trakunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
==== ntpd/refclock_wwvb.c ====
2010-02-03 04:58:31+00:00, davehart at shiny.ad.hartbrothers.com +10 -6
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
Fix widely cut-n-pasted bug in refclock shutdown after failed start.
--- 1.22/ntpd/refclock_wwvb.c 2009-10-26 22:15:42 -05:00
+++ 1.23/ntpd/refclock_wwvb.c 2010-02-02 23:58:31 -05:00
@@ -188,15 +188,15 @@ wwvb_start(
/*
* Open serial port. Use CLK line discipline, if available.
*/
- sprintf(device, DEVICE, unit);
+ snprintf(device, sizeof(device), DEVICE, unit);
if (-1 == (fd = refclock_open(device, SPEED232, LDISC_CLK)))
return (0);
/*
* Allocate and initialize unit structure
*/
- up = (struct wwvbunit *)emalloc(sizeof(struct wwvbunit));
- memset((char *)up, 0, sizeof(struct wwvbunit));
+ up = emalloc(sizeof(*up));
+ memset(up, 0, sizeof(*up));
pp = peer->procptr;
pp->unitptr = (caddr_t)up;
pp->io.clock_recv = wwvb_receive;
@@ -205,7 +205,9 @@ wwvb_start(
pp->io.fd = fd;
if (!io_addclock(&pp->io)) {
close(fd);
+ pp->io.fd = -1;
free(up);
+ pp->unitptr = NULL;
return (0);
}
@@ -214,7 +216,7 @@ wwvb_start(
*/
peer->precision = PRECISION;
pp->clockdesc = DESCRIPTION;
- memcpy((char *)&pp->refid, REFID, 4);
+ memcpy(&pp->refid, REFID, 4);
return (1);
}
@@ -233,8 +235,10 @@ wwvb_shutdown(
pp = peer->procptr;
up = (struct wwvbunit *)pp->unitptr;
- io_closeclock(&pp->io);
- free(up);
+ if (-1 != pp->io.fd)
+ io_closeclock(&pp->io);
+ if (NULL != up)
+ free(up);
}
==== ntpq/ntpq-subs.c ====
2010-02-03 04:58:31+00:00, davehart at shiny.ad.hartbrothers.com +28 -22
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.39.1.2/ntpq/ntpq-subs.c 2009-11-17 02:27:51 -05:00
+++ 1.39.2.1/ntpq/ntpq-subs.c 2010-02-02 23:58:31 -05:00
@@ -56,7 +56,7 @@ static void radiostatus (struct parse *,
static void pstatus (struct parse *, FILE *);
static long when (l_fp *, l_fp *, l_fp *);
-static char * prettyinterval (char *, long);
+static char * prettyinterval (char *, size_t, long);
static int doprintpeers (struct varlist *, int, int, int, char *, FILE *, int);
static int dogetpeers (struct varlist *, int, FILE *, int);
static void dopeers (int, FILE *, int);
@@ -1091,14 +1091,16 @@ printassoc(
break;
}
cnt = uinttoa(event_count);
- sprintf(buf,
- "%3d %5u %04x %3.3s %4s %4.4s %9.9s %11s %2s",
- i + 1, assoc_cache[i].assid, assoc_cache[i].status,
- conf, reach, auth, condition, last_event, cnt);
- bp = &buf[strlen(buf)];
- while (bp > buf && *(bp-1) == ' ')
- *(--bp) = '\0';
- (void) fprintf(fp, "%s\n", buf);
+ snprintf(buf, sizeof(buf),
+ "%3d %5u %04x %3.3s %4s %4.4s %9.9s %11s %2s",
+ i + 1, assoc_cache[i].assid,
+ assoc_cache[i].status, conf, reach, auth,
+ condition, last_event, cnt);
+ bp = buf + strlen(buf);
+ while (bp > buf && ' ' == bp[-1])
+ --bp;
+ bp[0] = '\0';
+ fprintf(fp, "%s\n", buf);
}
}
@@ -1296,6 +1298,7 @@ when(
static char *
prettyinterval(
char *buf,
+ size_t cb,
long diff
)
{
@@ -1306,24 +1309,24 @@ prettyinterval(
}
if (diff <= 2048) {
- (void) sprintf(buf, "%ld", (long int)diff);
+ snprintf(buf, cb, "%ld", diff);
return buf;
}
diff = (diff + 29) / 60;
if (diff <= 300) {
- (void) sprintf(buf, "%ldm", (long int)diff);
+ snprintf(buf, cb, "%ldm", diff);
return buf;
}
diff = (diff + 29) / 60;
if (diff <= 96) {
- (void) sprintf(buf, "%ldh", (long int)diff);
+ snprintf(buf, cb, "%ldh", diff);
return buf;
}
diff = (diff + 11) / 24;
- (void) sprintf(buf, "%ldd", (long int)diff);
+ snprintf(buf, cb, "%ldd", diff);
return buf;
}
@@ -1584,18 +1587,21 @@ doprintpeers(
else
c = flash2[CTL_PEER_STATVAL(rstatus) & 0x3];
if (numhosts > 1)
- (void) fprintf(fp, "%-*s ", maxhostlen, currenthost);
+ fprintf(fp, "%-*s ", maxhostlen, currenthost);
if (af == 0 || AF(&srcadr) == af) {
- strcpy(clock_name, nntohost(&srcadr));
-
- (void) fprintf(fp,
+ strncpy(clock_name, nntohost(&srcadr), sizeof(clock_name));
+ fprintf(fp,
"%c%-15.15s %-15.15s %2ld %c %4.4s %4.4s %3lo %7.7s %8.7s %7.7s\n",
c, clock_name, dstadr_refid, stratum, type,
- prettyinterval(whenbuf, when(&ts, &rec, &reftime)),
- prettyinterval(pollbuf, (int)poll_sec), reach,
- lfptoms(&estdelay, 3), lfptoms(&estoffset, 3),
- havevar[HAVE_JITTER] ? lfptoms(&estjitter, 3) :
- lfptoms(&estdisp, 3));
+ prettyinterval(whenbuf, sizeof(whenbuf),
+ when(&ts, &rec, &reftime)),
+ prettyinterval(pollbuf, sizeof(pollbuf),
+ (int)poll_sec),
+ reach, lfptoms(&estdelay, 3),
+ lfptoms(&estoffset, 3),
+ (havevar[HAVE_JITTER])
+ ? lfptoms(&estjitter, 3)
+ : lfptoms(&estdisp, 3));
return (1);
}
else
==== ntpq/ntpq.c ====
2010-02-03 04:58:31+00:00, davehart at shiny.ad.hartbrothers.com +23 -12
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
--- 1.97/ntpq/ntpq.c 2009-11-17 14:43:42 -05:00
+++ 1.97.1.1/ntpq/ntpq.c 2010-02-02 23:58:31 -05:00
@@ -3108,33 +3108,44 @@ tstflags(
u_long val
)
{
- register char *cb, *s;
+ register char *cp, *s;
+ size_t cb;
register int i;
register const char *sep;
sep = "";
i = 0;
- s = cb = &circ_buf[nextcb][0];
+ s = cp = circ_buf[nextcb];
if (++nextcb >= NUMCB)
- nextcb = 0;
+ nextcb = 0;
+ cb = sizeof(circ_buf[0]);
- sprintf(cb, "%02lx", val);
- cb += strlen(cb);
+ snprintf(cp, cb, "%02lx", val);
+ cp += strlen(cp);
+ cb -= strlen(cp);
if (!val) {
- strcat(cb, " ok");
- cb += strlen(cb);
+ strncat(cp, " ok", cb);
+ cp += strlen(cp);
+ cb -= strlen(cp);
} else {
- *cb++ = ' ';
- for (i = 0; i < 13; i++) {
+ if (cb) {
+ *cp++ = ' ';
+ cb--;
+ }
+ for (i = 0; i < COUNTOF(tstflagnames); i++) {
if (val & 0x1) {
- sprintf(cb, "%s%s", sep, tstflagnames[i]);
+ snprintf(cp, cb, "%s%s", sep,
+ tstflagnames[i]);
sep = ", ";
- cb += strlen(cb);
+ cp += strlen(cp);
+ cb -= strlen(cp);
}
val >>= 1;
}
}
- *cb = '\0';
+ if (cb)
+ *cp = '\0';
+
return s;
}
==== ports/winnt/ntpd/hopf_PCI_io.c ====
2010-02-03 04:58:31+00:00, davehart at shiny.ad.hartbrothers.com +173 -136
Convert many sprintf() calls to snprintf(), also strcpy(), strcat().
clean up indent mess.
--- 1.6/ports/winnt/ntpd/hopf_PCI_io.c 2004-11-29 22:26:45 -05:00
+++ 1.7/ports/winnt/ntpd/hopf_PCI_io.c 2010-02-02 23:58:31 -05:00
@@ -12,21 +12,21 @@
* Ignore nonstandard extension warning.
* This happens when including winioctl.h
*/
-#pragma warning( disable : 4201)
+#pragma warning(disable: 4201)
#define _FILESYSTEMFSCTL_
#include <config.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
+#include <stddef.h>
#include <winioctl.h>
#include "hopf_PCI_io.h"
-#include <stddef.h>
-#define ATL_PASSTHROUGH_READ_TOSIZE 3*sizeof(ULONG)
-#define ATL_PASSTHROUGH_READ_FROMSIZE 0
-#define IOCTL_ATLSOFT_PASSTHROUGH_READ CTL_CODE( \
+#define ATL_PASSTHROUGH_READ_TOSIZE (3 * sizeof(ULONG))
+#define ATL_PASSTHROUGH_READ_FROMSIZE 0
+#define IOCTL_ATLSOFT_PASSTHROUGH_READ CTL_CODE( \
FILE_DEVICE_UNKNOWN, \
0x805, \
METHOD_BUFFERED, \
@@ -35,68 +35,70 @@
HANDLE hDevice = NULL; // this is the handle to the PCI Device
-HANDLE hRdEvent;
-OVERLAPPED Rdoverlapped;
-OVERLAPPED *pRdOverlapped;
-
-ULONG iobuffer[256];
-DWORD cbReturned;
-BOOL HaveBoard = FALSE;
-struct{
+HANDLE hRdEvent;
+OVERLAPPED Rdoverlapped;
+OVERLAPPED * pRdOverlapped;
+
+ULONG iobuffer[256];
+DWORD cbReturned;
+BOOL HaveBoard = FALSE;
+
+struct {
ULONG region;
ULONG offset;
ULONG count;
- }io_params;
+} io_params;
-BOOL OpenHopfDevice()
+BOOL
+OpenHopfDevice(void)
{
- OSVERSIONINFO VersionInfo;
- ULONG deviceNumber;
- CHAR deviceName[255];
-
- VersionInfo.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
- GetVersionEx(&VersionInfo);
- switch(VersionInfo.dwPlatformId)
- {
- case VER_PLATFORM_WIN32_WINDOWS: // Win95/98
- return(FALSE); // "NTP does not support Win 95-98."
- break;
-
- case VER_PLATFORM_WIN32_NT: // WinNT
- deviceNumber=0;
- sprintf(deviceName,"\\\\.\\hclk6039%d",deviceNumber+1);
- hDevice=CreateFile(
- deviceName,
- GENERIC_WRITE|GENERIC_READ,
- FILE_SHARE_WRITE|FILE_SHARE_READ,
- NULL,
- OPEN_EXISTING,
- FILE_FLAG_DELETE_ON_CLOSE | FILE_FLAG_OVERLAPPED,
- NULL);
- break;
-
- default:
- hDevice=INVALID_HANDLE_VALUE;
- break;
-
- } // end switch
-
- if ( hDevice == INVALID_HANDLE_VALUE ) // the system didn't return a handle
- {
- return(FALSE); //"A handle to the driver could not be obtained properly"
- }
-
- hRdEvent=CreateEvent(NULL, // an event to be used for async transfers
- TRUE,
- FALSE,
- NULL);
+ OSVERSIONINFO VersionInfo;
+ ULONG deviceNumber;
+ CHAR deviceName[255];
+
+ VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+ GetVersionEx(&VersionInfo);
+ switch (VersionInfo.dwPlatformId) {
+
+ case VER_PLATFORM_WIN32_WINDOWS: // Win95/98
+ return FALSE; // "NTP does not support Win 95-98."
+ break;
+
+ case VER_PLATFORM_WIN32_NT: // WinNT
+ deviceNumber = 0;
+ snprintf(deviceName, sizeof(deviceName),
+ "\\\\.\\hclk6039%d", deviceNumber + 1);
+ hDevice = CreateFile(
+ deviceName,
+ GENERIC_WRITE | GENERIC_READ,
+ FILE_SHARE_WRITE | FILE_SHARE_READ,
+ NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_DELETE_ON_CLOSE | FILE_FLAG_OVERLAPPED,
+ NULL);
+ break;
+
+ default:
+ hDevice = INVALID_HANDLE_VALUE;
+ break;
+ } // end switch
+
+ if (INVALID_HANDLE_VALUE == hDevice) // the system didn't return a handle
+ return FALSE; //"A handle to the driver could not be obtained properly"
+
+ // an event to be used for async transfers
+ hRdEvent = CreateEvent(
+ NULL,
+ TRUE,
+ FALSE,
+ NULL);
- if ( hRdEvent == INVALID_HANDLE_VALUE )
- return(FALSE); // the system didn't return a handle
+ if (INVALID_HANDLE_VALUE == hRdEvent)
+ return FALSE; // the system didn't return a handle
- pRdOverlapped=&Rdoverlapped;
- pRdOverlapped->hEvent=hRdEvent;
+ pRdOverlapped = &Rdoverlapped;
+ pRdOverlapped->hEvent = hRdEvent;
HaveBoard = TRUE; // board installed and we have access
@@ -104,63 +106,76 @@ BOOL OpenHopfDevice()
} // end of OpenHopfDevice()
-BOOL CloseHopfDevice(){
-
+BOOL
+CloseHopfDevice(void)
+{
CloseHandle(hRdEvent);// When done, close the handle to the driver
- if (CloseHandle(hDevice)==TRUE) // unlink the driver using a CloseHandle call
- {
- return TRUE;
- }
- return FALSE; // "The driver handle could not be unlinked properly"
+ return CloseHandle(hDevice);
} // end of CloseHopfDevice()
-void ReadHopfDevice(){
+void
+ReadHopfDevice(void)
+{
+ if (!HaveBoard)
+ return;
- if (HaveBoard){
- DeviceIoControl(hDevice, IOCTL_ATLSOFT_PASSTHROUGH_READ, &io_params,ATL_PASSTHROUGH_READ_TOSIZE,
- iobuffer,ATL_PASSTHROUGH_READ_FROMSIZE+io_params.count*sizeof(ULONG),&cbReturned, pRdOverlapped);
- }
+ DeviceIoControl(
+ hDevice,
+ IOCTL_ATLSOFT_PASSTHROUGH_READ,
+ &io_params,
+ ATL_PASSTHROUGH_READ_TOSIZE,
+ iobuffer,
+ ATL_PASSTHROUGH_READ_FROMSIZE
+ + io_params.count * sizeof(ULONG),
+ &cbReturned,
+ pRdOverlapped
+ );
}
-
-
-void GetHardwareData(LPDWORD Data32,WORD Ofs)
+void
+GetHardwareData(
+ LPDWORD Data32,
+ WORD Ofs
+ )
{
io_params.region = 1;
io_params.offset = Ofs;
- io_params.count =1;
+ io_params.count = 1;
ReadHopfDevice();
*Data32 = iobuffer[0];
- return;
}
-void GetHopfTime(LPHOPFTIME Data,DWORD Offset)
+void
+GetHopfTime(
+ LPHOPFTIME Data,
+ DWORD Offset
+ )
{
io_params.region = 1;
io_params.offset = Offset;
- io_params.count =4;
+ io_params.count = 4;
ReadHopfDevice();
Data->wHour = 0;
Data->wMinute = 0;
Data->wSecond = 0;
- while (iobuffer[0] >= (60 * 60 * 1000)) {
- iobuffer[0] = iobuffer[0] - 60*60 *1000;
+ while (iobuffer[0] >= 60 * 60 * 1000) {
+ iobuffer[0] = iobuffer[0] - 60 * 60 * 1000;
Data->wHour++;
- }
- while (iobuffer[0] >= (60 * 1000)) {
- iobuffer[0] = iobuffer[0] - 60 *1000;
+ }
+ while (iobuffer[0] >= 60 * 1000) {
+ iobuffer[0] = iobuffer[0] - 60 * 1000;
Data->wMinute++;
- }
- while (iobuffer[0] >= (1000)) {
+ }
+ while (iobuffer[0] >= 1000) {
iobuffer[0] = iobuffer[0] - 1000;
Data->wSecond++;
- }
+ }
Data->wMilliseconds = LOWORD(iobuffer[0]);
Data->wDay = HIBYTE(HIWORD(iobuffer[1]));
Data->wMonth = LOBYTE(HIWORD(iobuffer[1]));
@@ -171,81 +186,95 @@ void GetHopfTime(LPHOPFTIME Data,DWORD O
io_params.region = 1;
io_params.offset += 0x08;
- io_params.count =1;
+ io_params.count = 1;
ReadHopfDevice();
Data->wStatus = LOBYTE(HIWORD(iobuffer[0]));
- return;
}
-void GetHopfLocalTime(LPHOPFTIME Data)
+void
+GetHopfLocalTime(
+ LPHOPFTIME Data
+ )
{
DWORD Offset = 0;
- GetHopfTime(Data,Offset);
- return;
+
+ GetHopfTime(Data, Offset);
}
-void GetHopfSystemTime(LPHOPFTIME Data)
+void
+GetHopfSystemTime(
+ LPHOPFTIME Data
+ )
{
DWORD Offset = 0x10;
- GetHopfTime(Data,Offset);
- return;
+
+ GetHopfTime(Data,Offset);
}
-void GetSatData(LPSATSTAT Data)
+void
+GetSatData(
+ LPSATSTAT Data
+ )
{
io_params.region = 1;
io_params.offset = 0xb0;
- io_params.count =5;
+ io_params.count = 5;
ReadHopfDevice();
- Data->wVisible= HIBYTE(HIWORD(iobuffer[0]));
- Data->wMode = LOBYTE(LOWORD(iobuffer[0]));
- Data->wSat0 = HIBYTE(HIWORD(iobuffer[1]));
- Data->wRat0 = LOBYTE(HIWORD(iobuffer[1]));
- Data->wSat1 = HIBYTE(LOWORD(iobuffer[1]));
- Data->wRat1 = LOBYTE(LOWORD(iobuffer[1]));
- Data->wSat2 = HIBYTE(HIWORD(iobuffer[2]));
- Data->wRat2 = LOBYTE(HIWORD(iobuffer[2]));
- Data->wSat3 = HIBYTE(LOWORD(iobuffer[2]));
- Data->wRat3 = LOBYTE(LOWORD(iobuffer[2]));
- Data->wSat4 = HIBYTE(HIWORD(iobuffer[3]));
- Data->wRat4 = LOBYTE(HIWORD(iobuffer[3]));
- Data->wSat5 = HIBYTE(LOWORD(iobuffer[3]));
- Data->wRat5 = LOBYTE(LOWORD(iobuffer[3]));
- Data->wSat6 = HIBYTE(HIWORD(iobuffer[4]));
- Data->wRat6 = LOBYTE(HIWORD(iobuffer[4]));
- Data->wSat7 = HIBYTE(LOWORD(iobuffer[4]));
- Data->wRat7 = LOBYTE(LOWORD(iobuffer[4]));
-
- return;
+ Data->wVisible = HIBYTE(HIWORD(iobuffer[0]));
+ Data->wMode = LOBYTE(LOWORD(iobuffer[0]));
+ Data->wSat0 = HIBYTE(HIWORD(iobuffer[1]));
+ Data->wRat0 = LOBYTE(HIWORD(iobuffer[1]));
+ Data->wSat1 = HIBYTE(LOWORD(iobuffer[1]));
+ Data->wRat1 = LOBYTE(LOWORD(iobuffer[1]));
+ Data->wSat2 = HIBYTE(HIWORD(iobuffer[2]));
+ Data->wRat2 = LOBYTE(HIWORD(iobuffer[2]));
+ Data->wSat3 = HIBYTE(LOWORD(iobuffer[2]));
+ Data->wRat3 = LOBYTE(LOWORD(iobuffer[2]));
+ Data->wSat4 = HIBYTE(HIWORD(iobuffer[3]));
+ Data->wRat4 = LOBYTE(HIWORD(iobuffer[3]));
+ Data->wSat5 = HIBYTE(LOWORD(iobuffer[3]));
+ Data->wRat5 = LOBYTE(LOWORD(iobuffer[3]));
+ Data->wSat6 = HIBYTE(HIWORD(iobuffer[4]));
+ Data->wRat6 = LOBYTE(HIWORD(iobuffer[4]));
+ Data->wSat7 = HIBYTE(LOWORD(iobuffer[4]));
+ Data->wRat7 = LOBYTE(LOWORD(iobuffer[4]));
}
-void GetDiffTime(LPLONG Data)
+
+void
+GetDiffTime(
+ LPLONG Data
+ )
{
io_params.region = 1;
io_params.offset = 0x0c;
- io_params.count =1;
+ io_params.count = 1;
ReadHopfDevice();
- *Data = iobuffer[0];
- return;
+ *Data = iobuffer[0];
}
-void GetPosition(LPGPSPOS Data){
+
+void
+GetPosition(
+ LPGPSPOS Data
+ )
+{
io_params.region = 1;
io_params.offset = 0x90; // Positionsdaten Länge
io_params.count = 1;
ReadHopfDevice();
- Data->wLongitude = iobuffer[0]; //in Millisekunden
+ Data->wLongitude = iobuffer[0]; //in Millisekunden
io_params.region = 1;
io_params.offset = 0xa0; // Positionsdaten Breite
io_params.count = 1;
@@ -254,20 +283,25 @@ void GetPosition(LPGPSPOS Data){
Data->wLatitude = iobuffer[0];
Data->wAltitude = 0;
- return;
}
-void GetHardwareVersion(LPCLOCKVER Data){
-int i;
+
+void
+GetHardwareVersion(
+ LPCLOCKVER Data
+ )
+{
+ int i;
+
io_params.region = 1;
io_params.offset = 0x50;
- io_params.count =12;
+ io_params.count = 12;
ReadHopfDevice();
- strcpy(Data->cVersion,"");
- iobuffer[13] =0;
- for (i=0; i < 13; i++){
+ Data->cVersion[0] = '\0';
+ iobuffer[13] = 0;
+ for (i = 0; i < 13; i++) {
Data->cVersion[i * 4 ] = HIBYTE(HIWORD(iobuffer[i]));
Data->cVersion[i * 4 + 1] = LOBYTE(HIWORD(iobuffer[i]));
Data->cVersion[i * 4 + 2] = HIBYTE(LOWORD(iobuffer[i]));
@@ -275,16 +309,19 @@ int i;
}
}
-void GetDCFAntenne(LPDCFANTENNE Data){
+
+void
+GetDCFAntenne(
+ LPDCFANTENNE Data
+ )
+{
io_params.region = 1;
- io_params.offset = 0xcc; //
+ io_params.offset = 0xcc;
io_params.count = 1;
ReadHopfDevice();
- Data->bStatus1 = HIBYTE(HIWORD(iobuffer[0])); //
- Data->bStatus = LOBYTE(HIWORD(iobuffer[0])); //
- Data->wAntValue = LOWORD(iobuffer[0]);
- return;
+ Data->bStatus1 = HIBYTE(HIWORD(iobuffer[0]));
+ Data->bStatus = LOBYTE(HIWORD(iobuffer[0]));
+ Data->wAntValue = LOWORD(iobuffer[0]);
}
-
==== ports/winnt/vs2008/libntp/libntp.vcproj ====
2010-02-03 04:58:31+00:00, davehart at shiny.ad.hartbrothers.com +6 -2
add reference to libntp/audio.c
--- 1.20.1.4/ports/winnt/vs2008/libntp/libntp.vcproj 2009-11-09 02:35:24 -05:00
+++ 1.20.1.5/ports/winnt/vs2008/libntp/libntp.vcproj 2010-02-02 23:58:31 -05:00
@@ -208,6 +208,10 @@
>
</File>
<File
+ RelativePath="..\..\..\..\libntp\audio.c"
+ >
+ </File>
+ <File
RelativePath="..\..\..\..\libntp\authkeys.c"
>
</File>
@@ -817,11 +821,11 @@
>
</File>
<File
- RelativePath="..\..\..\..\lib\isc\win32\include\isc\time.h"
+ RelativePath="..\..\include\sys\time.h"
>
</File>
<File
- RelativePath="..\..\include\sys\time.h"
+ RelativePath="..\..\..\..\lib\isc\win32\include\isc\time.h"
>
</File>
<File
More information about the bk-ntp-dev-send
mailing list