From: Dave Hart Date: Tue, 12 Apr 2011 06:01:57 +0000 (+0000) Subject: Remove remaining sprintf() calls except refclock_ripencc.c (which is X-Git-Tag: NTP_4_2_7P150~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=896914ddcad4366d3b057816792baf307a06b32a;p=thirdparty%2Fntp.git Remove remaining sprintf() calls except refclock_ripencc.c (which is kept out of --enable-all-clocks as a result), upstream libs which use sprintf() ony after careful buffer sizing, and ntp_proto.c. bk: 4da3ead5DcGKUDh099LhXtKjhFj3Rw --- diff --git a/ChangeLog b/ChangeLog index 447c93009..4187237d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,9 @@ * Remove never-used, incomplete ports/winnt/ntpd/refclock_trimbledc.[ch] * On systems without C99-compliant (v)snprintf(), use C99-snprintf replacements (http://www.jhweiss.de/software/snprintf.html) +* Remove remaining sprintf() calls except refclock_ripencc.c (which is + kept out of --enable-all-clocks as a result), upstream libs which use + sprintf() ony after careful buffer sizing, and ntp_proto.c. (4.2.7p149) 2011/04/11 Released by Harlan Stenn * [Bug 1881] describe the {+,-,s} characters in configure --help output. (4.2.7p148) 2011/04/09 Released by Harlan Stenn diff --git a/configure.ac b/configure.ac index 3d2842481..49fa71881 100644 --- a/configure.ac +++ b/configure.ac @@ -895,12 +895,6 @@ case "$ac_cv_func_recvmsg" in esac esac -case "$host" in - *-*-sunos4*) - AC_DEFINE([SPRINTF_CHAR], [1], [*s*printf() functions are char*]) - ;; -esac - AC_CACHE_CHECK( [number of arguments taken by setpgrp()], [ntp_cv_func_setpgrp_nargs], diff --git a/include/Makefile.am b/include/Makefile.am index a9070b0ea..61efd97fb 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -49,7 +49,6 @@ noinst_HEADERS = \ ntp_request.h \ ntp_rfc2553.h \ ntp_select.h \ - ntp_sprintf.h \ ntp_stdlib.h \ ntp_string.h \ ntp_syscall.h \ diff --git a/include/ntp_sprintf.h b/include/ntp_sprintf.h deleted file mode 100644 index a456a8925..000000000 --- a/include/ntp_sprintf.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Handle ancient char* *s*printf*() systems - */ - -#ifdef SPRINTF_CHAR -# define SPRINTF(x) strlen(sprintf/**/x) -# define SNPRINTF(x) strlen(snprintf/**/x) -# define VSNPRINTF(x) strlen(vsnprintf/**/x) -#else -# define SPRINTF(x) ((size_t)sprintf x) -# define SNPRINTF(x) ((size_t)snprintf x) -# define VSNPRINTF(x) ((size_t)vsnprintf x) -#endif diff --git a/lib/isc/inet_ntop.c b/lib/isc/inet_ntop.c index 997bfd9bf..febbfb35c 100644 --- a/lib/isc/inet_ntop.c +++ b/lib/isc/inet_ntop.c @@ -31,8 +31,6 @@ static char rcsid[] = #include #include -#include "ntp_sprintf.h" /* NTP local change, helps SunOS 4 */ - #define NS_INT16SZ 2 #define NS_IN6ADDRSZ 16 @@ -181,7 +179,7 @@ inet_ntop6(const unsigned char *src, char *dst, size_t size) tp += strlen(tp); break; } - tp += SPRINTF((tp, "%x", words[i])); /* NTP local change */ + tp += sprintf(tp, "%x", words[i]); } /* Was it a trailing run of 0x00's? */ if (best.base != -1 && (best.base + best.len) == diff --git a/libntp/bsd_strerror.c b/libntp/bsd_strerror.c index 9d8ae8e4f..5ace9aa48 100644 --- a/libntp/bsd_strerror.c +++ b/libntp/bsd_strerror.c @@ -39,9 +39,10 @@ strerror( static char ebuf[20]; if ((unsigned int)errnum < sys_nerr) - return(sys_errlist[errnum]); - (void)sprintf(ebuf, "Unknown error: %d", errnum); - return(ebuf); + return sys_errlist[errnum]; + snprintf(ebuf, sizeof(ebuf), "Unknown error: %d", errnum); + + return ebuf; } #else int strerror_bs; diff --git a/libntp/snprintf.c b/libntp/snprintf.c index 3864ef073..4ea9aed66 100644 --- a/libntp/snprintf.c +++ b/libntp/snprintf.c @@ -123,10 +123,10 @@ * HW_WANT_RPL_SNPRINTF * HW_WANT_RPL_VASPRINTF * HW_WANT_RPL_ASPRINTF - * HAVE_VSNPRINTF - * HAVE_SNPRINTF - * HAVE_VASPRINTF - * HAVE_ASPRINTF + * HAVE_VSNPRINTF // define to 1 #if HW_WANT_RPL_VSNPRINTF + * HAVE_SNPRINTF // define to 1 #if HW_WANT_RPL_SNPRINTF + * HAVE_VASPRINTF // define to 1 #if HW_WANT_RPL_VASPRINTF + * HAVE_ASPRINTF // define to 1 #if HW_WANT_RPL_ASPRINTF * HAVE_STDARG_H * HAVE_STDDEF_H * HAVE_STDINT_H diff --git a/libparse/ieee754io.c b/libparse/ieee754io.c index 8f3175e36..61bc8533b 100644 --- a/libparse/ieee754io.c +++ b/libparse/ieee754io.c @@ -89,14 +89,15 @@ fmt_flt( unsigned long ch ) { - char *buf; + char *buf; - LIB_GETBUF(buf); - sprintf(buf, "%c %s %s %s", sign ? '-' : '+', - fmt_blong(ch, 11), - fmt_blong(mh, 20), - fmt_blong(ml, 32)); - return buf; + LIB_GETBUF(buf); + snprintf(buf, LIB_BUFLENGTH, "%c %s %s %s", sign ? '-' : '+', + fmt_blong(ch, 11), + fmt_blong(mh, 20), + fmt_blong(ml, 32)); + + return buf; } static char * @@ -105,15 +106,18 @@ fmt_hex( int length ) { - char *buf; - int i; + char * buf; + char hex[4]; + int i; + + LIB_GETBUF(buf); + buf[0] = '\0'; + for (i = 0; i < length; i++) { + snprintf(hex, sizeof(hex), "%02x", bufp[i]); + strlcat(buf, hex, LIB_BUFLENGTH); + } - LIB_GETBUF(buf); - for (i = 0; i < length; i++) - { - sprintf(buf+i*2, "%02x", bufp[i]); - } - return buf; + return buf; } #endif diff --git a/ntpd/refclock_mx4200.c b/ntpd/refclock_mx4200.c index 44b3e2463..c9422290d 100644 --- a/ntpd/refclock_mx4200.c +++ b/ntpd/refclock_mx4200.c @@ -67,8 +67,6 @@ # include #endif -#include "ntp_sprintf.h" - #ifndef HAVE_STRUCT_PPSCLOCKEV struct ppsclockev { # ifdef HAVE_STRUCT_TIMESPEC diff --git a/ntpd/refclock_tpro.c b/ntpd/refclock_tpro.c index 5a2255fd5..dc5f5c004 100644 --- a/ntpd/refclock_tpro.c +++ b/ntpd/refclock_tpro.c @@ -160,7 +160,7 @@ tpro_poll( * proper format, we declare bad format and exit. Note: we * can't use the sec/usec conversion produced by the driver, * since the year may be suspect. All format error checking is - * done by the sprintf() and sscanf() routines. + * done by the snprintf() and sscanf() routines. * * Note that the refclockproc usec member has now become nsec. * We could either multiply the read-in usec value by 1000 or diff --git a/ntpd/refclock_tt560.c b/ntpd/refclock_tt560.c index 7aa2180e7..94fdef14f 100644 --- a/ntpd/refclock_tt560.c +++ b/ntpd/refclock_tt560.c @@ -76,14 +76,14 @@ tt560_start( { register struct tt560unit *up; struct refclockproc *pp; - char device[20]; - int fd; - caddr_t membase; + char device[20]; + int fd; + caddr_t membase; /* * Open TT560 device */ - (void)sprintf(device, DEVICE, unit); + snprintf(device, sizeof(device), DEVICE, unit); fd = open(device, O_RDWR); if (fd == -1) { msyslog(LOG_ERR, "tt560_start: open of %s: %m", device); @@ -195,9 +195,9 @@ tt560_poll( * proper format, we declare bad format and exit. Note: we * can't use the sec/usec conversion produced by the driver, * since the year may be suspect. All format error checking is - * done by the sprintf() and sscanf() routines. + * done by the snprintf() and sscanf() routines. */ - sprintf(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->hun_day, tp->tens_day, tp->unit_day, tp->tens_hour, tp->unit_hour, diff --git a/ntpd/refclock_wwv.c b/ntpd/refclock_wwv.c index a2f693a0f..08a5754cd 100644 --- a/ntpd/refclock_wwv.c +++ b/ntpd/refclock_wwv.c @@ -1569,7 +1569,7 @@ wwv_endpoc( } } if (pp->sloppyclockflag & CLK_FLAG4) { - sprintf(tbuf, + snprintf(tbuf, sizeof(tbuf), "wwv2 %04x %5.0f %5.1f %5d %4d %4d %4d %4.0f %7.2f", up->status, up->epomax, up->eposnr, mepoch, up->avgint, maxrun, mcount - zcount, dtemp, @@ -2021,7 +2021,7 @@ wwv_rsec( } if ((pp->sloppyclockflag & CLK_FLAG4) && !(up->status & DSYNC)) { - sprintf(tbuf, + snprintf(tbuf, sizeof(tbuf), "wwv3 %2d %04x %3d %4d %5.0f %5.1f %5.0f %5.1f %5.0f", nsec, up->status, up->gain, up->yepoch, up->epomax, up->eposnr, up->datsig, up->datsnr, bit); diff --git a/ntpdate/ntptimeset.c b/ntpdate/ntptimeset.c index 46c2f8f1d..fa622a973 100644 --- a/ntpdate/ntptimeset.c +++ b/ntpdate/ntptimeset.c @@ -4,7 +4,7 @@ * GOAL: * The goal of ntptime is to set the current time on system startup * to the best possible time using the network very wisely. It is assumed - * that after a resonable time has been sett then ntp daemon will + * that after a reasonable time has been set then ntp daemon will * maintain it. * * PROBLEM DOMAIN: @@ -51,7 +51,7 @@ * NOTE: Please do not have this program print out every minute some line, * of output. If this happens and the environment is in trouble then * many pages of paper on many different machines will be filled up. - * Save some tress in your lifetime. + * Save some trees in your lifetime. * * CONCLUSION: * The behavior of the program derived from these three issues should be @@ -318,9 +318,6 @@ static void init_io P((void)); static int sendpkt P((struct sockaddr_in *dest, struct pkt *pkt, int len)); void input_handler P((l_fp *xts)); static void printserver P((register struct server *pp, FILE *fp)); -#if !defined(HAVE_VSPRINTF) -int vsprintf P((char *str, const char *fmt, va_list ap)); -#endif #ifdef HAVE_SIGNALED_IO extern void wait_for_signal P((void)); @@ -592,10 +589,8 @@ ntptimesetmain( exit(1); } if (!authistrusted(sys_authkey)) { - char buf[10]; - - (void) sprintf(buf, "%lu", (unsigned long)sys_authkey); - msyslog(LOG_ERR, "authentication key %s unknown", buf); + msyslog(LOG_ERR, "authentication key %lu unknown", + (u_long)sys_authkey); exit(1); } } @@ -2137,23 +2132,3 @@ printserver( (void) fprintf(fp, "offset %s\n\n", lfptoa(&pp->offset, 6)); } - -#if !defined(HAVE_VSPRINTF) -int -vsprintf( - char *str, - const char *fmt, - va_list ap - ) -{ - FILE f; - int len; - - f._flag = _IOWRT+_IOSTRG; - f._ptr = str; - f._cnt = 32767; - len = _doprnt(fmt, ap, &f); - *f._ptr = 0; - return (len); -} -#endif diff --git a/ports/winnt/include/config.h b/ports/winnt/include/config.h index b8658a88a..4ffe3ea96 100644 --- a/ports/winnt/include/config.h +++ b/ports/winnt/include/config.h @@ -262,8 +262,8 @@ typedef int socklen_t; * to other names */ #define inline __inline -#define vsnprintf _vsnprintf -#define snprintf _snprintf +/* #define vsnprintf _vsnprintf */ +/* #define snprintf _snprintf */ #define stricmp _stricmp #define strcasecmp _stricmp #define isascii __isascii @@ -390,6 +390,8 @@ typedef __int32 int32_t; /* define a typedef for int32_t */ #define HW_WANT_RPL_VSNPRINTF 1 #define HW_WANT_RPL_SNPRINTF 1 +#define HAVE_VSNPRINTF 1 +#define HAVE_SNPRINTF 1 typedef char *caddr_t; diff --git a/ports/winnt/libntp/syslog.c b/ports/winnt/libntp/syslog.c index 2a2915a20..6b82e924e 100644 --- a/ports/winnt/libntp/syslog.c +++ b/ports/winnt/libntp/syslog.c @@ -102,7 +102,7 @@ syslog(int level, const char *fmt, ...) { str[0] = buf; va_start(ap, fmt); - vsprintf(buf, fmt, ap); + vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); /* Make sure that the channel is open to write the event */ diff --git a/ports/winnt/ntpd/hopf_PCI_io.c b/ports/winnt/ntpd/hopf_PCI_io.c index 171b7a7d4..a1ba200f1 100644 --- a/ports/winnt/ntpd/hopf_PCI_io.c +++ b/ports/winnt/ntpd/hopf_PCI_io.c @@ -21,6 +21,8 @@ #include #include #include + +#include "ntp_stdlib.h" #include "hopf_PCI_io.h" diff --git a/ports/winnt/ntpd/refclock_trimbledc.c b/ports/winnt/ntpd/refclock_trimbledc.c deleted file mode 100644 index c90b52687..000000000 --- a/ports/winnt/ntpd/refclock_trimbledc.c +++ /dev/null @@ -1,292 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#if defined(REFCLOCK) && defined(CLOCK_TRIMBLEDC) - -#include "refclock_trimbledc.h" -extern int debug; - -static int trimbledc_start (int, struct peer *); -static void trimbledc_shutdown (int, struct peer *); -static void trimbledc_receive (struct recvbuf *); -static void trimbledc_poll (int, struct peer *); -static void trimbledc_io (char, int, unsigned char *, l_fp*, struct trimbledc_unit *); - - -/* - * Transfer vector - */ -struct refclock refclock_trimbledc = { - trimbledc_start, /* start up driver */ - trimbledc_shutdown, /* shut down driver */ - trimbledc_poll, /* transmit poll message */ - noentry, /* not used */ - noentry, /* initialize driver (not used) */ - noentry, /* not used */ - NOFLAGS /* not used */ -}; - - -/* - * trimbledc_start - open the devices and initialize data for processing - */ -static int -trimbledc_start ( - int unit, - struct peer *peer - ) -{ - register struct trimbledc_unit *up; - struct refclockproc *pp; - int fd; - char gpsdev[20]; - - struct termios tio; -#ifdef SYS_WINNT - (void) sprintf(gpsdev, DEVICE, unit); -#else - (void) sprintf(gpsdev, DEVICE, unit + 1); -#endif - /* - * Open serial port. - */ - fd = refclock_open(gpsdev, SPEED232, LDISC_RAW); - if (fd == -1) { - msyslog(LOG_ERR,"Trimble (%d) start: open %s failed: %m", - unit, gpsdev); - return 0; - } - - msyslog(LOG_NOTICE, "Trimble (%d) fd: %d dev: %s", unit, fd, gpsdev); - - if (tcgetattr(fd, &tio) < 0) { - msyslog(LOG_ERR, - "Trimble (%d) tcgetattr(fd, &tio): %m",unit); - return (0); - } - - tio.c_cflag |= (PARENB|PARODD); - tio.c_iflag &= ~ICRNL; - - if (tcsetattr(fd, TCSANOW, &tio) == -1) { - msyslog(LOG_ERR, "Trimble (%d) tcsetattr(fd, &tio): %m",unit); - return 0; - } - - /* - * Allocate and initialize unit structure - */ - if (!(up = (struct trimbledc_unit *) - emalloc(sizeof(struct trimbledc_unit)))) { - (void) close(fd); - return (0); - } - memset((char *)up, 0, sizeof(struct trimbledc_unit)); - - pp = peer->procptr; - pp->io.clock_recv = trimbledc_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); - } - - /* - * Initialize miscellaneous variables - */ - pp->unitptr = (caddr_t)up; - pp->clockdesc = DESCRIPTION; - - peer->precision = PRECISION; - peer->sstclktype = CTL_SST_TS_UHF; - peer->minpoll = TRIMBLEDC_MINPOLL; - peer->maxpoll = TRIMBLEDC_MAXPOLL; - memcpy((char *)&pp->refid, REFID, 4); - - up->leap_status = 0; - up->unit = unit; - up->io_ptr[0] = up->io_ptr[1] = 0; - - return 1; -} - - -/* - * trimbledc_shutdown - shut down the clock - */ -static void -trimbledc_shutdown ( - int unit, - struct peer *peer - ) -{ - register struct trimbledc_unit *up; - struct refclockproc *pp; - pp = peer->procptr; - up = (struct trimbledc_unit *)pp->unitptr; - io_closeclock(&pp->io); - free(up); -} - - - -/* - * TSIP_decode - decode the TSIP data packets - */ -static int -trimbledc_decode ( - struct peer *peer - ) -{ -#ifdef DEBUG - double lat, lon, alt; -#endif - int st, ts; - long secint; - double secs; - double secfrac; - unsigned short event = 0; - - register struct trimbledc_unit *up; - struct refclockproc *pp; - - pp = peer->procptr; - up = (struct trimbledc_unit *)pp->unitptr; - - /* - * Check the time packet, decode its contents. - * If the timecode has invalid length or is not in - * proper format, declare bad format and exit. - */ - - if (up->rpt_buf[0] ==0x41) - /* standard time packet - GPS time and GPS week number */ - return 0; - - - refclock_report(peer, CEVNT_BADREPLY); - up->polled = -1; -#ifdef DEBUG - if (debug) - printf("TRIMBLEDC_decode: unit %d: bad packet %02x-%02x event %d len %d\n", - up->unit, up->rpt_buf[0] & 0xff, mb(0) & 0xff, - event, up->rpt_cnt); -#endif - return 0; -} - -/* - * trimbledc__receive - receive data from the serial interface - */ - -static void -trimbledc_receive ( - struct recvbuf *rbufp - ) -{ - register struct trimbledc_unit *up; - struct refclockproc *pp; - struct peer *peer; - - /* - * Initialize pointers and read the timecode and timestamp. - */ - peer = (struct peer *)rbufp->recv_srcclock; - pp = peer->procptr; - up = (struct trimbledc_unit *)pp->unitptr; - - - for (;FALSE;) { - trimbledc_io(pp->sloppyclockflag & CLK_FLAG2, rbufp->recv_length, - &rbufp->recv_buffer, &pp->lastrec, up); - - - - - (void) sprintf(pp->a_lastcode,"%4d %03d %02d:%02d:%02d.%06ld", - pp->year,pp->day,pp->hour,pp->minute, pp->second,pp->usec); - pp->lencode = 24; - - if (!refclock_process(pp)) { - refclock_report(peer, CEVNT_BADTIME); - -#ifdef DEBUG - if (debug) - printf("trimbledc_receive: unit %d: refclock_process failed!\n", - up->unit); -#endif - continue; - } - - record_clock_stats(&peer->srcadr, pp->a_lastcode); - -#ifdef DEBUG - if (debug) - if (debug) - printf("trimbledc_receive: unit %d: %s\n", - up->unit, prettydate(&pp->lastrec)); -#endif - - refclock_receive(peer); - } -} - - -/* - * trimbledc_poll - called by the transmit procedure - * - */ -static void -trimbledc_poll ( - int unit, - struct peer *peer - ) -{ - struct trimbledc_unit *up; - struct refclockproc *pp; - - pp = peer->procptr; - up = (struct trimbledc_unit *)pp->unitptr; - - pp->polls++; - if (up->polled > 0) /* last reply never arrived or error */ - refclock_report(peer, CEVNT_TIMEOUT); - - up->polled = 2; /* synchronous packet + 1 event */ - -#ifdef DEBUG - if (debug) - printf("trimbledc_poll: unit %d: polling %s\n", unit, - (pp->sloppyclockflag & CLK_FLAG2) ? - "synchronous packet" : "event"); -#endif - - if (pp->sloppyclockflag & CLK_FLAG2) - return; /* using synchronous packet input */ - -// if (HW_poll(pp) < 0) - refclock_report(peer, CEVNT_FAULT); -} - - -static void -trimbledc_io ( - char noevents, - int buflen, /* bytes in buffer to process */ - unsigned char *bufp, /* receive buffer */ - l_fp* t_in, /* receive time stamp */ - struct trimbledc_unit *up /* pointer to unit data structure */ - ) -{ - -} - - - - -#endif /* REFCLOCK */ diff --git a/ports/winnt/ntpd/refclock_trimbledc.h b/ports/winnt/ntpd/refclock_trimbledc.h deleted file mode 100644 index f53ff7f7d..000000000 --- a/ports/winnt/ntpd/refclock_trimbledc.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * refclock_trimbledc - clock driver for the Trimble Data Collector compatible - * GPS receivers (4000, 4700, 4800, 7400, ...) - * - * Greg Brackley (greg@trimble.co.nz) - */ - -#ifndef _REFCLOCK_TRIMBLEDC_H -#define _REFCLOCK_TRIMBLEDC_H - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#if defined HAVE_SYS_MODEM_H -#include -#define TIOCMSET MCSETA -#define TIOCMGET MCGETA -#define TIOCM_RTS MRTS -#endif - -#ifdef HAVE_TERMIOS_H -#include -#endif - -#ifdef HAVE_SYS_IOCTL_H -#include -#endif - -#include "ntpd.h" -#include "ntp_io.h" -#include "ntp_control.h" -#include "ntp_refclock.h" -#include "ntp_unixtime.h" -#include "ntp_stdlib.h" - -/* - * GPS Definitions - */ -#define DESCRIPTION "Trimble Data Collector GPS" /* Long name */ -#define PRECISION (-20) /* precision assumed (about 1 us) */ -#define REFID "GPS\0" /* reference ID */ -#define NSAMPLES 1 -#define NSKEEP 1 -#define TRIMBLEDC_MINPOLL 4 -#define TRIMBLEDC_MAXPOLL 4 - -/* - * I/O Definitions - */ -#if !defined SYS_WINNT -#define DEVICE "/dev/trimbledc%d" /* device name and unit */ -#else -#define DEVICE "\\\\.\\COM%d" /* device name and unit */ -#endif -#define SPEED232 B9600 /* uart speed (9600 baud) */ - -#define POLL_AVG 10 /* number of samples to average code delay */ -#define DC_IO_BUFSIZE 512 /* IO buffer */ -#define DC_MAXLEN 260 /* maximum length TSIP packet */ - -/* - * Leap-Insert and Leap-Delete are encoded as follows: - * PALISADE_UTC_TIME set and PALISADE_LEAP_PENDING set: INSERT leap - * PALISADE_UTC_TIME clear and PALISADE_LEAP_PENDING set: DELETE leap - */ - -#define PALISADE_LEAP_WARNING 0x04 /* GPS Leap Warning (see ICD-200) */ -#define PALISADE_LEAP_PENDING 0x02 /* Leap Pending (24 hours) */ -#define PALISADE_UTC_TIME 0x01 /* UTC time available */ - -#define mb(_X_) (up->rpt_buf[(_X_ + 1)]) /* shortcut for buffer access */ - -/* Conversion Definitions */ -#define GPS_PI (3.1415926535898) -#define R2D (180.0/GPS_PI) - -typedef enum TrimbleDcParseState { - - TrimbleParseStateAck, - TrimbleParseStateNak, - TrimbleParseStateData, - -} TrimbleDcParseState; - -struct trimbledc_unit { - int unit; /* NTP refclock unit number */ - int polled; /* flag to detect noreplies */ - char leap_status; /* leap second flag */ - TrimbleDcParseState rpt_status; - short rpt_cnt; - char rpt_buf[DC_MAXLEN]; - char io_buf[DC_IO_BUFSIZE]; - short io_ptr[2]; /* 0 = head, 1 = tail */ -}; - -#endif /* _REFCLOCK_TRIMBLEDC_H */ diff --git a/ports/winnt/vs2003/libntp.vcproj b/ports/winnt/vs2003/libntp.vcproj index 827e563d8..56d0671bf 100644 --- a/ports/winnt/vs2003/libntp.vcproj +++ b/ports/winnt/vs2003/libntp.vcproj @@ -1575,9 +1575,6 @@ - - diff --git a/ports/winnt/vs2005/libntp.vcproj b/ports/winnt/vs2005/libntp.vcproj index 8cf2feab8..d7df6717f 100644 --- a/ports/winnt/vs2005/libntp.vcproj +++ b/ports/winnt/vs2005/libntp.vcproj @@ -765,10 +765,6 @@ RelativePath="..\..\..\include\ntp_select.h" > - - diff --git a/ports/winnt/vs2008/libntp/libntp.vcproj b/ports/winnt/vs2008/libntp/libntp.vcproj index 2c9de4e90..6dbd6ee16 100644 --- a/ports/winnt/vs2008/libntp/libntp.vcproj +++ b/ports/winnt/vs2008/libntp/libntp.vcproj @@ -820,10 +820,6 @@ RelativePath="..\..\..\..\include\ntp_select.h" > - - diff --git a/ports/winnt/vs2008/ntpd/ntpd.vcproj b/ports/winnt/vs2008/ntpd/ntpd.vcproj index 43b6963ea..184fc3c12 100644 --- a/ports/winnt/vs2008/ntpd/ntpd.vcproj +++ b/ports/winnt/vs2008/ntpd/ntpd.vcproj @@ -914,6 +914,10 @@ RelativePath="..\..\..\..\ntpd\refclock_true.c" > + + diff --git a/util/audio-pcm.c b/util/audio-pcm.c index 6f2e4fa84..cbaf0f2f4 100644 --- a/util/audio-pcm.c +++ b/util/audio-pcm.c @@ -94,8 +94,8 @@ main( ) char *actl = ac_dev; int devmask = 0, recmask = 0, recsrc = 0; - (void)sprintf(ai_dev, AI_DEV, unit); - (void)sprintf(ac_dev, AC_DEV, unit); + snprintf(ai_dev, sizeof(ai_dev), AI_DEV, unit); + snprintf(ac_dev, sizeof(ac_dev), AC_DEV, unit); /* * Open audio device. Do not complain if not there. diff --git a/util/sht.c b/util/sht.c index b993de907..2a83f401c 100644 --- a/util/sht.c +++ b/util/sht.c @@ -62,7 +62,7 @@ getShmTime ( #else char buf[10]; LPSECURITY_ATTRIBUTES psec=0; - sprintf (buf,"NTP%d",unit); + snprintf (buf, sizeof(buf), "NTP%d", unit); SECURITY_DESCRIPTOR sd; SECURITY_ATTRIBUTES sa; HANDLE shmid; diff --git a/util/tg.c b/util/tg.c index 0d0fce688..8a96a816a 100644 --- a/util/tg.c +++ b/util/tg.c @@ -374,8 +374,8 @@ main( case WWV: printf("year %d day %d time %02d:%02d:%02d tone %d\n", year, day, hour, minute, second, tone); - sprintf(code, "%01d%03d%02d%02d%01d", year / 10, day, - hour, minute, year % 10); + snprintf(code, sizeof(code), "%01d%03d%02d%02d%01d", + year / 10, day, hour, minute, year % 10); printf("%s\n", code); ptr = 8; for (i = 0; i <= second; i++) { @@ -431,16 +431,17 @@ main( year++; } if (encode == WWV) { - sprintf(code, "%01d%03d%02d%02d%01d", - year / 10, day, hour, minute, year % - 10); + snprintf(code, sizeof(code), + "%01d%03d%02d%02d%01d", year / 10, + day, hour, minute, year % 10); printf("\n%s\n", code); ptr = 8; } } if (encode == IRIG) { - sprintf(code, "%04x%04d%06d%02d%02d%02d", 0, - year, day, hour, minute, second); + snprintf(code, sizeof(code), + "%04x%04d%06d%02d%02d%02d", 0, year, day, + hour, minute, second); printf("%s\n", code); ptr = 19; } diff --git a/util/tg2.c b/util/tg2.c index db8de0656..e388f20f0 100644 --- a/util/tg2.c +++ b/util/tg2.c @@ -1098,7 +1098,7 @@ main( printf("WWV time signal, starting point:\n"); printf(" Year = %02d, Day of year = %03d, Time = %02d:%02d:%02d, Minute tone = %d Hz, Hour tone = %d Hz.\n", Year, DayOfYear, Hour, Minute, Second, tone, HourTone); - sprintf(code, "%01d%03d%02d%02d%01d", + snprintf(code, sizeof(code), "%01d%03d%02d%02d%01d", Year / 10, DayOfYear, Hour, Minute, Year % 10); if (Verbose) { @@ -1371,8 +1371,9 @@ main( Year++; } if (encode == WWV) { - sprintf(code, "%01d%03d%02d%02d%01d", - Year / 10, DayOfYear, Hour, Minute, Year % 10); + snprintf(code, sizeof(code), + "%01d%03d%02d%02d%01d", Year / 10, + DayOfYear, Hour, Minute, Year % 10); if (Verbose) printf("\n Year = %2.2d, Day of year = %3d, Time = %2.2d:%2.2d:%2.2d, Code = %s", Year, DayOfYear, Hour, Minute, Second, code); @@ -1441,17 +1442,20 @@ main( ControlFunctions = 0; /* - YearDay HourMin Sec - sprintf(code, "%04x%04d%06d%02d%02d%02d", + YearDay HourMin Sec + snprintf(code, sizeof(code), "%04x%04d%06d%02d%02d%02d", 0, Year, DayOfYear, Hour, Minute, Second); */ if (IrigIncludeYear) { - sprintf(ParityString, "%04X%02d%04d%02d%02d%02d", - ControlFunctions & 0x7FFF, Year, DayOfYear, Hour, Minute, Second); - } - else { - sprintf(ParityString, "%04X%02d%04d%02d%02d%02d", - ControlFunctions & 0x7FFF, 0, DayOfYear, Hour, Minute, Second); + snprintf(ParityString, sizeof(ParityString), + "%04X%02d%04d%02d%02d%02d", + ControlFunctions & 0x7FFF, Year, + DayOfYear, Hour, Minute, Second); + } else { + snprintf(ParityString, sizeof(ParityString), + "%04X%02d%04d%02d%02d%02d", + ControlFunctions & 0x7FFF, + 0, DayOfYear, Hour, Minute, Second); } if (IrigIncludeIeee) @@ -1501,14 +1505,19 @@ main( ControlFunctions |= ((ParityValue & 0x01) << 14); if (IrigIncludeYear) { - /* YearDay HourMin Sec*/ - sprintf(code, "%05X%05X%02d%04d%02d%02d%02d", - StraightBinarySeconds, ControlFunctions, Year, DayOfYear, Hour, Minute, Second); - } - else { - /* YearDay HourMin Sec*/ - sprintf(code, "%05X%05X%02d%04d%02d%02d%02d", - StraightBinarySeconds, ControlFunctions, 0, DayOfYear, Hour, Minute, Second); + snprintf(code, sizeof(code), + /* YearDay HourMin Sec */ + "%05X%05X%02d%04d%02d%02d%02d", + StraightBinarySeconds, + ControlFunctions, Year, DayOfYear, + Hour, Minute, Second); + } else { + snprintf(code, sizeof(code), + /* YearDay HourMin Sec */ + "%05X%05X%02d%04d%02d%02d%02d", + StraightBinarySeconds, + ControlFunctions, 0, DayOfYear, + Hour, Minute, Second); } if (Debug)