]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1455] ntpd does not try /etc/ntp.audio as documented.
authorDave Hart <hart@ntp.org>
Wed, 3 Feb 2010 04:58:33 +0000 (04:58 +0000)
committerDave Hart <hart@ntp.org>
Wed, 3 Feb 2010 04:58:33 +0000 (04:58 +0000)
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.

bk: 4b690279XH7_NKsG8uPbWDVeQPvJ1Q

41 files changed:
ChangeLog
lib/isc/win32/interfaceiter.c
libntp/audio.c
libntp/findconfig.c
libntp/humandate.c
libntp/modetoa.c
libntp/prettydate.c
libntp/uglydate.c
libntp/uinttoa.c
ntpd/ntp_control.c
ntpd/refclock_arbiter.c
ntpd/refclock_arc.c
ntpd/refclock_as2201.c
ntpd/refclock_atom.c
ntpd/refclock_bancomm.c
ntpd/refclock_chronolog.c
ntpd/refclock_chu.c
ntpd/refclock_dumbclock.c
ntpd/refclock_gpsvme.c
ntpd/refclock_heath.c
ntpd/refclock_hopfpci.c
ntpd/refclock_hopfser.c
ntpd/refclock_hpgps.c
ntpd/refclock_irig.c
ntpd/refclock_jjy.c
ntpd/refclock_jupiter.c
ntpd/refclock_leitch.c
ntpd/refclock_msfees.c
ntpd/refclock_mx4200.c
ntpd/refclock_palisade.c
ntpd/refclock_parse.c
ntpd/refclock_pcf.c
ntpd/refclock_pst.c
ntpd/refclock_shm.c
ntpd/refclock_tpro.c
ntpd/refclock_trak.c
ntpd/refclock_wwvb.c
ntpq/ntpq-subs.c
ntpq/ntpq.c
ports/winnt/ntpd/hopf_PCI_io.c
ports/winnt/vs2008/libntp/libntp.vcproj

index a004ccc24b74cada0af9a165e5a9e4c2033c2bda..7860c17ba8c65578b0c330f46b6e6d9a08f023c3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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@ntp.org>
index 903fa213d334eecdcb3d36cd27511aa564f4ce1e..a6cd7229bee229cb6d7d2213fc2113b4e1f268ec 100644 (file)
@@ -373,14 +373,15 @@ internal_current(isc_interfaceiter_t *iter) {
 
        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 *iter) {
                                  &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 *iter) {
                    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));
index ab5723eac84691e5b9bb7c43ac86807158627627..a685fe9521ada1516fcbfb94cc93c791b7cfec21 100644 (file)
@@ -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. */
index ecf6a4bc204c5070f76ddbc1c5ac9140dbec132a..562c01764c3c18cbf6d6445d3ddb570b143dae5b 100644 (file)
@@ -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 {
index e3614cf20a18c784c0383128f9e1809b2b558d0c..36510c5293804c29078732a66d4c81c5edd872bf 100644 (file)
@@ -15,19 +15,20 @@ extern const char *months[];        /* prettydate.c */
 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;
 }
index 405aef8550c152d0ce41478e7b46da199459f497..9daf1bb1239f1f5e81446430835e61bdb6bbfa09 100644 (file)
@@ -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;
        }
 
index 09f358fe53ca226b0c344cd3b7532665675044e4..1503a2ce87e308341eeb23e7439b8d9bcaaac024 100644 (file)
@@ -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;
 }
index 676a5fdde786005e36e474b5ab7b7697a58b1347..b2da9c0a6c39eb28714daf9963d8163de359250b 100644 (file)
@@ -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;
 }
index be48ea5146a6a83f261d07ea5c8f6da2092e7775..ab63926cdc79fedf758ee1d238304d49b2aad8cd 100644 (file)
@@ -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;
 }
index 7a32ddc3840a7edc82a58335f809b6f287d25760..d87b5afbf60181555a659de3a0a699ea21ae3cc4 100644 (file)
@@ -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;
index f360d37fca269cc0ff718c8d77f638d14625e04c..35bee70dd60da015dbf8393c02570694424e2ce9 100644 (file)
@@ -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);
 }
 
 
index 7f1fcbf507b51fa20b40fdbec73324f5502b0cbc..e0a2afeb48409e19fb8703c2fa0c1103147fdce6 100644 (file)
@@ -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);
 }
 
 /*
index a48d6531952764d8511060e75c031be13d43675e..163c2afee1a246287574dd8ba47944eefe12f2cd 100644 (file)
@@ -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);
 }
 
 
index 569c16a6ec626e76e8c6dd1bbcd64f6ee85ac795..d8a9d3e27add6ddba3d27234daee6acf0db8cbc1 100644 (file)
@@ -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);
        }
 }
index 0e9ceb00202a53e500a76b1d9f0604d526e4869a..3bb0ffea430a77bf551cb15187c5eeba7cd76eb5 100644 (file)
@@ -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;
        }
index d7dace0582a53320c30bf21ea97e87b950c9c11e..ba4f60b4ed62ef58c43fd019d0f939d8e29f4da0 100644 (file)
@@ -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);
 }
 
 
index cce406f7291ac3dbb99a8ffd10d5b0192026b885..de3488631e9024c488b67c6fdf53b4f66f295ef1 100644 (file)
@@ -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) {
index d85849eac5b7a6d076fad75bc2322094d4ef302b..32e56f83d2b41aea299dff0000abb6fe81529c8c 100644 (file)
@@ -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);
 }
 
 
index 9f9e85c9fa8dcd216af1684e763a8c225d538961..c3322fdebf2de872510624889a9cbd7349f84cfe 100644 (file)
@@ -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  */
index f9b2b3e64687a2f62d6c7e42e537ee67282c86e8..cd74eca3173dac278574cc54ec9d210b2b6a8594 100644 (file)
@@ -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);
 }
 
 
index 81c186d168bd21d3bfb05b29ad0a0df7034e10c0..284e3011c90954e32a01625bc6d24f51a3735f07 100644 (file)
@@ -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);
index a94402a37c7d5f79d9c0d356ad87b9b39ccf320f..48eea0022bb7c7a8d2ecf32e958d94758060cb56 100644 (file)
@@ -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,
index 08f709fd36c75cc3315f28b4e37a6232c65cdd9e..5867a1d7b278e92e025418d3ff9cd1f1168714f5 100644 (file)
@@ -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);
 }
 
 
index 0e6cfca9bea3e4c50a62ba3cf4e0a77e1b567d5d..8ff17ccf946a1a6879190067f399305ee8041f4d 100644 (file)
@@ -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,
index 1ac09d50f808aa1db81d212f5ab0de5f8417bb14..13f56defdadaf9f820724fc1e2c43d1bbbb018d8 100644 (file)
@@ -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 *peer )
 
        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 ) ) {
index 583e31bc014c3225749464adb1e74cb49e47e8f9..844d24f59daa1c1b93729a0d45f221cc9327f942 100644 (file)
@@ -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, struct jheader *hp)
        }
 
        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);
index fe6f7725d6293aae5189a5064c4b267dec23cf34..52b65085c8f020eca60025d7ab7dc9a199b43ba0 100644 (file)
@@ -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;
        }
 
index 98034b5870989de31708141292445f6e537bc53a..1b25c1c38c4e45a41d940dd799929da9bc1f2cb5 100644 (file)
@@ -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),
index 77ccedd6cfe2c1990cabf170ada3f090bc822f9c..f863dca08d98d039e45d9cbd751b4fca97810ee5 100644 (file)
@@ -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,
index ff7ab8badd00290f19733cf689cdb02ca4105002..7e9f59fbcf71ef56828dbf2ffe435d32501a5fdc 100644 (file)
@@ -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)) {
index b6470d65196b1a0981de20d1eb8859c2f4f7ed90..24d27f9b1a105cd4b8704e79a665aca59c39daa5 100644 (file)
@@ -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;
                                }
index 6f7d58e5779c2153b7bdebbe207050b74988ce51..fcc12be0706a7ce8b9577fc6c09e4683f2200ee7 100644 (file)
@@ -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
index 4eaa50166863c37e8a02358ef5d2a4fdeb738279..bd208c72590ffe2f2c2fe09445f765687d59ecba 100644 (file)
@@ -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);
 }
 
 
index c110c3826da0741e3e83b62f82a36359d3222824..b73e899766d349bbf6f249ccd36bce082aae94a4 100644 (file)
@@ -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);
 }
 
 
index 860f8bab525e9dac802d74c8f0bb951fd9b69025..86764d3f7a2574b2e38dc79bdb09d5dcc85a9903 100644 (file)
@@ -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",
index 3a4a54e653eb89908428402342327c2cdbc4de3f..ddb86de845b0c1fb5c0eb230789c8258ce68324b 100644 (file)
@@ -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);
 }
 
 
index e65af9aff7b9156c25f1eed583714475437a5d1b..e327fb16f7127d9a3b5b59470bed0dfcb4378cd4 100644 (file)
@@ -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);
 }
 
 
index c016c79a7bea7d425a0613bc91b250c3f33b35cc..9cad688958cf0bfb9f96ed02e5e1db4ec3de6dd0 100644 (file)
@@ -56,7 +56,7 @@ static        void    radiostatus (struct parse *, FILE *);
 
 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
index d1ebc414ea058fc919936f69644a8bfdc585bb98..29380fc9eb4d76812cf9b092dfdae56bdffcc8c9 100644 (file)
@@ -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;
 }
 
index c50088b5cb9428b8e1b456e7e26751e0d7cba15d..880825ddd1ac6afdbcf87ee482b028f0e8c8be75 100644 (file)
  * 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,        \
 
 HANDLE hDevice = NULL; // this is the handle to the PCI Device
 
-HANDLE                         hRdEvent;
-OVERLAPPED                     Rdoverlapped;
-OVERLAPPED                     *pRdOverlapped;
+HANDLE         hRdEvent;
+OVERLAPPED     Rdoverlapped;
+OVERLAPPED *   pRdOverlapped;
 
-ULONG                          iobuffer[256];
-DWORD                          cbReturned;
-BOOL                           HaveBoard = FALSE; 
-struct{
+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);  
-
-                       if ( hRdEvent == INVALID_HANDLE_VALUE 
-                               return(FALSE);  // the system didn't return a handle
-
-                       pRdOverlapped=&Rdoverlapped;
-                       pRdOverlapped->hEvent=hRdEvent;
+       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 (INVALID_HANDLE_VALUE == hRdEvent
+               return FALSE;  // the system didn't return a handle
+
+       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(){
-
-    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);
-       }
+void
+ReadHopfDevice(void)
+{
+       if (!HaveBoard)
+               return;
+
+       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 Offset)
        
        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]);
 }
 
-
index b80e53899f26ddc8e3fcc57a3ecc65bae1820c68..1fcdbeae84fa322700123f46985016e645c04b55 100644 (file)
                                RelativePath="..\..\..\..\libntp\atouint.c"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\..\..\libntp\audio.c"
+                               >
+                       </File>
                        <File
                                RelativePath="..\..\..\..\libntp\authkeys.c"
                                >
                                >
                        </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