]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 2980] reduce number of warnings
authorJuergen Perlinger <perlinger@ntp.org>
Sat, 5 Dec 2015 20:28:19 +0000 (20:28 +0000)
committerJuergen Perlinger <perlinger@ntp.org>
Sat, 5 Dec 2015 20:28:19 +0000 (20:28 +0000)
 - string formatting(arguments should be literals)
 - applying constness where necessary
 - removing bad consts that are superfluous
 - avoid signed/unsigned clashes in conditionals (either by cast or type change)
 - signed/unsigned and promotion conflicts
 - add prototypes for function pointer tables
 - force unsigned argument promotion in calls to 'ctype' functions (is{digit,cntrl,...})

bk: 566348e3T9RaQjcLAr5jZOzeEyQN1A

23 files changed:
ChangeLog
include/parse.h
ntpd/ntp_config.c
ntpd/ntp_io.c
ntpd/ntp_scanner.c
ntpd/ntp_timer.c
ntpd/refclock_chu.c
ntpd/refclock_gpsdjson.c
ntpd/refclock_jjy.c
ntpd/refclock_shm.c
ntpq/ntpq-subs.c
ntpq/ntpq.c
sntp/libopts/configfile.c
sntp/libopts/enum.c
sntp/libopts/find.c
sntp/libopts/init.c
sntp/libopts/load.c
sntp/libopts/makeshell.c
sntp/libopts/nested.c
sntp/libopts/parse-duration.c
sntp/libopts/reset.c
sntp/libopts/save.c
sntp/libopts/tokenize.c

index b4a8ab7659c2485c7f1a66c94846698ad5912c05..afa932c503014ba0565289aba9707813d1364754 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -45,6 +45,8 @@
               lots of clients. perlinger@ntp.org
 * [Bug 2971] ntpq bails on ^C: select fails: Interrupted system call
   - changed stacked/nested handling of CTRL-C. perlinger@ntp.org
+* [Bug 2980] reduce number of warnings. perlinger@ntp.org
+  - integrated several patches from Havard Eidnes (he@uninett.no)
 * Unity cleanup for FreeBSD-6.4.  Harlan Stenn.
 * Unity test cleanup.  Harlan Stenn.
 * Libevent autoconf pthread fixes for FreeBSD-10.  Harlan Stenn.
index 9b1ffb2274255192726065f760493e602f8ec19f..02dbb3021904c11e885478db694b6b2630738ad7 100644 (file)
@@ -107,9 +107,9 @@ extern unsigned int splclock (void);
 /*
  * some constants useful for GPS time conversion
  */
-#define GPSORIGIN       2524953600UL                /* NTP origin - GPS origin in seconds */
-#define GPSWRAP         990U                        /* assume week count less than this in the previous epoch */
-#define GPSWEEKS        1024U                       /* number of weeks until the GPS epch rolls over */
+#define GPSORIGIN       2524953600UL         /* NTP origin - GPS origin in seconds */
+#define GPSWRAP         990                  /* assume week count less than this in the previous epoch */
+#define GPSWEEKS        1024                 /* number of weeks until the GPS epch rolls over */
 
 /*
  * state flags
index 1c754bd1613d8d5a126362dc8df70f07e597c159..8b3483202813e80228fff2af065ceb0f1f2f11be 100644 (file)
@@ -53,6 +53,8 @@
 #include "ntp_parser.h"
 #include "ntpd-opts.h"
 
+extern int yyparse(void);
+
 /* Bug 2817 */
 #if defined(HAVE_SYS_MMAN_H)
 # include <sys/mman.h>
index dd23459dff3a46eecc8d74939e7daef45a2df35e..05ab48beeb777f5064da368a3e56c1d670ce633f 100644 (file)
@@ -3265,7 +3265,7 @@ read_refclock_packet(
        /* TALOS-CAN-0064: avoid signed/unsigned clashes that can lead
         * to buffer overrun and memory corruption
         */
-       if (rp->datalen <= 0 || rp->datalen > sizeof(rb->recv_space))
+       if (rp->datalen <= 0 || (size_t)rp->datalen > sizeof(rb->recv_space))
                read_count = sizeof(rb->recv_space);
        else
                read_count = (u_int)rp->datalen;
index 49adf6bfb767a4aab5ddfbb190afefebbf15b18d..631c218b1567e13cb370369ac7edcc8a5c40d10b 100644 (file)
@@ -669,7 +669,7 @@ int
 yylex(void)
 {
        static follby   followedby = FOLLBY_TOKEN;
-       int             i;
+       size_t          i;
        int             instring;
        int             yylval_was_set;
        int             converted;
index 03084a353622a4559a3186347fbdc3319a2a8056..55570958bb22984cbf56566c813d0aded0ce442b 100644 (file)
@@ -572,8 +572,7 @@ check_leapsec(
                                DPRINTF(1, ("*** leapsec_query: setting leap_smear interval %li, begin %.0f, end %.0f\n",
                                        leap_smear.interval, leap_smear.intv_start, leap_smear.intv_end));
                        }
-               }
-               else {
+               } else {
                        if (leap_smear.interval)
                                DPRINTF(1, ("*** leapsec_query: clearing leap_smear interval\n"));
                        leap_smear.interval = 0;
@@ -655,10 +654,10 @@ check_leapsec(
                sys_tai = lsdata.tai_offs;
          } else {
 #ifdef AUTOKEY
-               update_autokey = (sys_tai != lsdata.tai_offs);
+                 update_autokey = (sys_tai != (u_int)lsdata.tai_offs);
 #endif
-               lsprox  = lsdata.proximity;
-               sys_tai = lsdata.tai_offs;
+                 lsprox  = lsdata.proximity;
+                 sys_tai = lsdata.tai_offs;
          }
        }
 
index 1f02a1c1f4a7504af9e1aa6ce60c1cbf162af80c..d745c816768d2a8bd23ef27180edbb6eff70ae1d 100644 (file)
@@ -1264,7 +1264,7 @@ chu_a(
                        offset = up->charstamp;
                else if (k > 0)
                        i = 1;
-               for (; i < nchar && i < k + 10; i++) {
+               for (; i < nchar && (i - 10) < k; i++) {
                        up->tstamp[up->ntstamp] = up->cstamp[i];
                        L_SUB(&up->tstamp[up->ntstamp], &offset);
                        L_ADD(&offset, &up->charstamp);
index c2bf09a805e8ddc82dcd9c5c4d71a0c911718f55..24a15e7f62aa8a6869409163220759b1ea64cf10 100644 (file)
@@ -377,17 +377,6 @@ static int16_t clamped_precision(int rawprec);
  * local / static stuff
  */
 
-/* The logon string is actually the ?WATCH command of GPSD, using JSON
- * data and selecting the GPS device name we created from our unit
- * number. We have an old a newer version that request PPS (and TOFF)
- * transmission.
- * Note: These are actually format strings!
- */
-static const char * const s_req_watch[2] = {
-       "?WATCH={\"device\":\"%s\",\"enable\":true,\"json\":true};\r\n",
-       "?WATCH={\"device\":\"%s\",\"enable\":true,\"json\":true,\"pps\":true};\r\n"
-};
-
 static const char * const s_req_version =
     "?VERSION;\r\n";
 
@@ -1147,7 +1136,7 @@ json_token_skip(
        const json_ctx * ctx,
        tok_ref          tid)
 {
-       if (tid >= 0 && tid < ctx->ntok) {
+       if (tid >= 0 && (u_int)tid < ctx->ntok) {
                int len = ctx->tok[tid].size;
                /* For arrays and objects, the size is the number of
                 * ITEMS in the compound. Thats the number of objects in
@@ -1172,7 +1161,10 @@ json_token_skip(
                        ++tid;
                        break;
                }
-               if (tid > ctx->ntok) /* Impossible? Paranoia rulez. */
+               /* The next condition should never be true, but paranoia
+                * prevails...
+                */
+               if (tid < 0 || (u_int)tid > ctx->ntok)
                        tid = ctx->ntok;
        }
        return tid;
@@ -1200,7 +1192,7 @@ json_object_lookup(
                        tid = json_token_skip(ctx, tid); /* skip val */
                } else if (strcmp(key, ctx->buf + ctx->tok[tid].start)) {
                        tid = json_token_skip(ctx, tid+1); /* skip key+val */
-               } else if (what < 0 || what == ctx->tok[tid+1].type) {
+               } else if (what < 0 || (u_int)what == ctx->tok[tid+1].type) {
                        return tid + 1;
                } else {
                        break;
@@ -1513,8 +1505,14 @@ process_version(
        if (up->fl_watch)
                return;
 
+       /* The logon string is actually the ?WATCH command of GPSD,
+        * using JSON data and selecting the GPS device name we created
+        * from our unit number. We have an old a newer version that
+        * request PPS (and TOFF) transmission.
+        */
        snprintf(up->buffer, sizeof(up->buffer),
-                s_req_watch[up->pf_toff != 0], up->device);
+                "?WATCH={\"device\":\"%s\",\"enable\":true,\"json\":true%s};\r\n",
+                up->device, (up->pf_toff ? ",\"pps\":true" : ""));
        buf = up->buffer;
        len = strlen(buf);
        log_data(peer, "send", buf, len);
index fef829ca071b26f191e238172556ef0cf27f8127..fc51fd9ee4b544b2bc230678501a5e3f25c41cb3 100644 (file)
  */
 
 struct jjyRawDataBreak {
-       char    *pString ;
-       int     iLength ;
+       const char *    pString ;
+       int             iLength ;
 } ;
 
 #define        MAX_TIMESTAMP   6
@@ -627,7 +627,7 @@ jjy_receive ( struct recvbuf *rbufp )
 #ifdef DEBUG
        printf( "\nrefclock_jjy.c : %s : Len=%d  ", sFunctionName, pp->lencode ) ;
        for ( i = 0 ; i < pp->lencode ; i ++ ) {
-               if ( iscntrl( pp->a_lastcode[i] & 0x7F ) ) {
+               if ( iscntrl( (u_char)(pp->a_lastcode[i] & 0x7F) ) ) {
                        printf( "<x%02X>", pp->a_lastcode[i] & 0xFF ) ;
                } else {
                        printf( "%c", pp->a_lastcode[i] ) ;
@@ -702,7 +702,7 @@ jjy_receive ( struct recvbuf *rbufp )
                                up->iLineBufLen ++ ;
 
                                /* Copy printable characters */
-                               if ( ! iscntrl( up->sRawBuf[i] ) ) {
+                               if ( ! iscntrl( (u_char)up->sRawBuf[i] ) ) {
                                        up->sTextBuf[up->iTextBufLen] = up->sRawBuf[i] ;
                                        up->iTextBufLen ++ ;
                                }
@@ -1154,12 +1154,13 @@ jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp )
        struct refclockproc *pp ;
        struct peer         *peer;
 
-       char    *pBuf, sLog [ 100 ] ;
-       int     iLen ;
-       int     rc ;
+       char *          pBuf ;
+       char            sLog [ 100 ] ;
+       int             iLen ;
+       int             rc ;
 
-       const char *pCmd ;
-       int     iCmdLen ;
+       const char *    pCmd ;
+       int             iCmdLen ;
 
        /* Initialize pointers  */
 
@@ -1359,8 +1360,8 @@ jjy_poll_tristate_jjy01  ( int unit, struct peer *peer )
        struct refclockproc *pp ;
        struct jjyunit      *up ;
 
-       const char *pCmd ;
-       int     iCmdLen ;
+       const char *    pCmd ;
+       int             iCmdLen ;
 
        pp = peer->procptr;
        up = pp->unitptr ;
@@ -2010,12 +2011,13 @@ jjy_receive_tristate_gpsclock01 ( struct recvbuf *rbufp )
        struct refclockproc *pp ;
        struct peer         *peer;
 
-       char    *pBuf, sLog [ 100 ] ;
-       int     iLen ;
-       int     rc ;
+       char *          pBuf ;
+       char            sLog [ 100 ] ;
+       int             iLen ;
+       int             rc ;
 
-       const char      *pCmd ;
-       int     iCmdLen ;
+       const char *    pCmd ;
+       int             iCmdLen ;
 
        /* Initialize pointers */
 
@@ -2239,8 +2241,8 @@ jjy_poll_tristate_gpsclock01 ( int unit, struct peer *peer )
        struct refclockproc *pp ;
        struct jjyunit      *up ;
 
-       const char      *pCmd ;
-       int     iCmdLen ;
+       const char *    pCmd ;
+       int             iCmdLen ;
 
        pp = peer->procptr ;
        up = pp->unitptr ;
@@ -2576,7 +2578,7 @@ static    int     teljjy_bye_ignore       ( struct peer *peer, struct refclockproc *, struct
 static int     teljjy_bye_disc         ( struct peer *peer, struct refclockproc *, struct jjyunit * ) ;
 static int     teljjy_bye_modem        ( struct peer *peer, struct refclockproc *, struct jjyunit * ) ;
 
-static int ( *pTeljjyHandler [ ] [ 5 ] ) ( ) =
+static int ( *pTeljjyHandler [ ] [ 5 ] ) ( struct peer *, struct refclockproc *, struct jjyunit *) =
 {                      /*STATE_IDLE           STATE_DAILOUT       STATE_LOGIN           STATE_CONNECT       STATE_BYE        */
 /* NULL       */       { teljjy_idle_ignore , teljjy_dial_ignore, teljjy_login_ignore, teljjy_conn_ignore, teljjy_bye_ignore },
 /* START      */       { teljjy_idle_dialout, teljjy_dial_ignore, teljjy_login_ignore, teljjy_conn_ignore, teljjy_bye_ignore },
@@ -2715,12 +2717,12 @@ jjy_start_telephone ( int unit, struct peer *peer, struct jjyunit *up )
 
        iNumberOfDigitsOfPhoneNumber = iCommaCount = iCommaPosition = iFirstThreeDigitsCount = 0 ;
        for ( i = 0 ; i < strlen( sys_phone[0] ) ; i ++ ) {
-               if ( isdigit( *(sys_phone[0]+i) ) ) {
+               if ( isdigit( (u_char)sys_phone[0][i] ) ) {
                        if ( iFirstThreeDigitsCount < sizeof(sFirstThreeDigits)-1 ) {
-                               sFirstThreeDigits[iFirstThreeDigitsCount++] = *(sys_phone[0]+i) ;
+                               sFirstThreeDigits[iFirstThreeDigitsCount++] = sys_phone[0][i] ;
                        }
                        iNumberOfDigitsOfPhoneNumber ++ ;
-               } else if ( *(sys_phone[0]+i) == ',' ) {
+               } else if ( sys_phone[0][i] == ',' ) {
                        iCommaCount ++ ;
                        if ( iCommaCount > 1 ) {
                                msyslog( LOG_ERR, "refclock_jjy.c : jjy_start_telephone : phone in the ntpd.conf should be zero or one comma." ) ;
@@ -2729,7 +2731,7 @@ jjy_start_telephone ( int unit, struct peer *peer, struct jjyunit *up )
                        }
                        iFirstThreeDigitsCount = 0 ;
                        iCommaPosition = i ;
-               } else if ( *(sys_phone[0]+i) != '-' ) {
+               } else if ( sys_phone[0][i] != '-' ) {
                        msyslog( LOG_ERR, "refclock_jjy.c : jjy_start_telephone : phone in the ntpd.conf should be a number or a hyphen." ) ;
                        up->bInitError = TRUE ;
                        return 1 ;
@@ -3213,8 +3215,8 @@ static int
 teljjy_login_login ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
 {
 
-       char    *pCmd ;
-       int     iCmdLen ;
+       const char *    pCmd ;
+       int             iCmdLen ;
 
        DEBUG_TELJJY_PRINTF( "teljjy_login_login" ) ;
 
@@ -3290,8 +3292,8 @@ static int
 teljjy_conn_send ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
 {
 
-       const char      *pCmd ;
-       int     i, iLen, iNextClockState ;
+       const char *    pCmd ;
+       int             i, iLen, iNextClockState ;
 
        DEBUG_TELJJY_PRINTF( "teljjy_conn_send" ) ;
 
@@ -3527,7 +3529,7 @@ static int
 teljjy_conn_silent ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
 {
 
-       const char      *pCmd ;
+       const char *    pCmd ;
 
        DEBUG_TELJJY_PRINTF( "teljjy_conn_silent" ) ;
 
@@ -3665,7 +3667,7 @@ static    int     modem_esc_data          ( struct peer *, struct refclockproc *, struct jjyu
 static int     modem_esc_silent        ( struct peer *, struct refclockproc *, struct jjyunit * ) ;
 static int     modem_esc_disc          ( struct peer *, struct refclockproc *, struct jjyunit * ) ;
 
-static int ( *pModemHandler [ ] [ 5 ] ) ( ) =
+static int ( *pModemHandler [ ] [ 5 ] ) ( struct peer *, struct refclockproc *, struct jjyunit * ) =
 {                              /*STATE_DISCONNECT   STATE_INITIALIZE   STATE_DAILING       STATE_CONNECT      STATE_ESCAPE     */
 /* NULL                 */     { modem_disc_ignore, modem_init_ignore, modem_dial_ignore , modem_conn_ignore, modem_esc_ignore },
 /* INITIALIZE           */     { modem_disc_init  , modem_init_start , modem_dial_ignore , modem_conn_ignore, modem_esc_ignore },
@@ -3993,10 +3995,11 @@ static int
 modem_init_resp00 ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
 {
 
-       char    *pCmd, cBuf [ 46 ] ;
-       int     iCmdLen ;
-       int     iErrorCorrection, iSpeakerSwitch, iSpeakerVolume ;
-       int     iNextModemState = STAY_MODEM_STATE ;
+       const char *    pCmd ;
+       char            cBuf [ 46 ] ;
+       int             iCmdLen ;
+       int             iErrorCorrection, iSpeakerSwitch, iSpeakerVolume ;
+       int             iNextModemState = STAY_MODEM_STATE ;
 
        DEBUG_MODEM_PRINTF( "modem_init_resp00" ) ;
 
@@ -4031,7 +4034,7 @@ modem_init_resp00 ( struct peer *peer, struct refclockproc *pp, struct jjyunit *
                }
 
                pCmd = cBuf ;
-               snprintf( pCmd, sizeof(cBuf), "ATM%dL%d\r\n", iSpeakerSwitch, iSpeakerVolume ) ;
+               snprintf( cBuf, sizeof(cBuf), "ATM%dL%d\r\n", iSpeakerSwitch, iSpeakerVolume ) ;
                break ;
 
        case 3 :
@@ -4060,7 +4063,7 @@ modem_init_resp00 ( struct peer *peer, struct refclockproc *pp, struct jjyunit *
                }
 
                pCmd = cBuf ;
-               snprintf( pCmd, sizeof(cBuf), "AT\\N%d\r\n", iErrorCorrection ) ;
+               snprintf( cBuf, sizeof(cBuf), "AT\\N%d\r\n", iErrorCorrection ) ;
                break ;
 
        case 7 :
@@ -4251,8 +4254,8 @@ static int
 modem_esc_escape ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
 {
 
-       char    *pCmd ;
-       int     iCmdLen ;
+       const char *    pCmd ;
+       int             iCmdLen ;
 
        DEBUG_MODEM_PRINTF( "modem_esc_escape" ) ;
 
@@ -4317,8 +4320,8 @@ static int
 modem_esc_disc ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
 {
 
-       char    *pCmd ;
-       int     iCmdLen ;
+       const char *    pCmd ;
+       int             iCmdLen ;
 
        DEBUG_MODEM_PRINTF( "modem_esc_disc" ) ;
 
@@ -4349,9 +4352,9 @@ static void
 jjy_write_clockstats ( struct peer *peer, int iMark, const char *pData )
 {
 
-       char    sLog [ 100 ] ;
-       char    *pMark ;
-       int     iMarkLen, iDataLen ;
+       char            sLog [ 100 ] ;
+       const char *    pMark ;
+       int             iMarkLen, iDataLen ;
 
        switch ( iMark ) {
        case JJY_CLOCKSTATS_MARK_JJY :
index f3e7f519ddc87bc31474cd81dc5c64fb579d799e..f031a395cb993aec45c41f2fb2b3005e145cf556 100644 (file)
@@ -600,7 +600,7 @@ shm_timer(
                     cd.year, cd.month, cd.monthday,
                     cd.hour, cd.minute, cd.second,
                     (long)shm_stat.tvt.tv_nsec);
-       pp->lencode = (c < sizeof(pp->a_lastcode)) ? c : 0;
+       pp->lencode = (c > 0 && (size_t)c < sizeof(pp->a_lastcode)) ? c : 0;
 
        /* check 1: age control of local time stamp */
        tt = shm_stat.tvc.tv_sec - shm_stat.tvr.tv_sec;
index 438c7ca58a65054702a0e0ddf60797f330d30d47..9e84aaf965aeac4ffab9b39c3ff414b9c454de83 100644 (file)
@@ -2861,7 +2861,7 @@ collect_mru_list(
                                 ri, sptoa(&recent->addr), ri,
                                 recent->last.l_ui, recent->last.l_uf);
                        chars = strlen(buf);
-                       if (REQ_ROOM <= chars)
+                       if ((size_t)REQ_ROOM <= chars)
                                break;
                        memcpy(req, buf, chars + 1);
                        req += chars;
index 5b3c9cb807b7fa144af95479ef2eabc9ae031d5e..fa2f648fad5e9854dc4188902229d174c7bd44f9 100644 (file)
@@ -218,7 +218,7 @@ static      void    outputarr       (FILE *, char *, int, l_fp *);
 static int     assoccmp        (const void *, const void *);
 static void    on_ctrlc        (void);
        u_short varfmt          (const char *);
-
+static int     my_easprintf    (char**, const char *, ...) NTP_PRINTF(2, 3);
 void   ntpq_custom_opt_handler (tOptions *, tOptDesc *);
 
 #ifdef OPENSSL
@@ -472,7 +472,7 @@ ntpqmain(
 
        {
            char *list;
-           char *msg, *fmt;
+           char *msg;
 
            list = list_digest_names();
            for (icmd = 0; icmd < sizeof(builtins)/sizeof(builtins[0]); icmd++) {
@@ -486,13 +486,15 @@ ntpqmain(
 
 #ifdef OPENSSL
            builtins[icmd].desc[0] = "digest-name";
-           fmt = "set key type to use for authenticated requests, one of:%s";
+           my_easprintf(&msg,
+                        "set key type to use for authenticated requests, one of:%s",
+                        list);
 #else
            builtins[icmd].desc[0] = "md5";
-           fmt = "set key type to use for authenticated requests (%s)";
+           my_easprintf(&msg,
+                        "set key type to use for authenticated requests (%s)",
+                        list);
 #endif
-           msg = emalloc(strlen(fmt) + strlen(list) - strlen("%s") +1);
-           sprintf(msg, fmt, list);
            builtins[icmd].comment = msg;
            free(list);
        }
@@ -3615,3 +3617,41 @@ on_ctrlc(void)
                if ((*ctrlc_stack[--size])())
                        break;
 }
+
+static int
+my_easprintf(
+       char **         ppinto,
+       const char *    fmt   ,
+       ...
+       )
+{
+       va_list va;
+       int     prc;
+       size_t  len = 128;
+       char *  buf = emalloc(len);
+
+  again:
+       /* Note: we expect the memory allocation to fail long before the
+        * increment in buffer size actually overflows.
+        */
+       buf = (buf) ? erealloc(buf, len) : emalloc(len);
+
+       va_start(va, fmt);
+       prc = vsnprintf(buf, len, fmt, va);
+       va_end(va);
+
+       if (prc < 0) {
+               /* might be very old vsnprintf. Or actually MSVC... */
+               len += len >> 1;
+               goto again;
+       }
+       if ((size_t)prc >= len) {
+               /* at least we have the proper size now... */
+               len = (size_t)prc + 1;
+               goto again;
+       }
+       if ((size_t)prc < (len - 32))
+               buf = erealloc(buf, (size_t)prc + 1);
+       *ppinto = buf;
+       return prc;
+}
index 03156ca6d8896eb735cba5017c4d17b0cfc1e1c2..8244371e56be7883288ae957eb0445c7418c5a2b 100644 (file)
@@ -182,9 +182,9 @@ optionFindValue(const tOptDesc * odesc, char const * name, char const * val)
     }
 
     else do {
-        tArgList * argl  = odesc->optCookie;
-        int        argct = argl->useCt;
-        void **    poptv = (void **)(argl->apzArgs);
+        tArgList *    argl  = odesc->optCookie;
+        int           argct = argl->useCt;
+        const void ** poptv = VOIDP(argl->apzArgs);
 
         if (argct == 0) {
             errno = ENOENT;
@@ -192,7 +192,7 @@ optionFindValue(const tOptDesc * odesc, char const * name, char const * val)
         }
 
         if (name == NULL) {
-            res = (tOptionValue *)*poptv;
+            res = (const tOptionValue *)*poptv;
             break;
         }
 
@@ -249,7 +249,7 @@ optionFindNextValue(const tOptDesc * odesc, const tOptionValue * pPrevVal,
                     char const * pzName, char const * pzVal)
 {
     bool old_found = false;
-    tOptionValue * res = NULL;
+    const tOptionValue * res = NULL;
 
     (void)pzName;
     (void)pzVal;
@@ -264,12 +264,12 @@ optionFindNextValue(const tOptDesc * odesc, const tOptionValue * pPrevVal,
     }
 
     else do {
-        tArgList * argl = odesc->optCookie;
-        int        ct   = argl->useCt;
-        void **   poptv = (void **)argl->apzArgs;
+        tArgList *    argl  = odesc->optCookie;
+        int           ct    = argl->useCt;
+        const void ** poptv = VOIDP(argl->apzArgs);
 
         while (--ct >= 0) {
-            tOptionValue * pOV = *(poptv++);
+            const tOptionValue * pOV = *(poptv++);
             if (old_found) {
                 res = pOV;
                 break;
@@ -315,8 +315,8 @@ optionFindNextValue(const tOptDesc * odesc, const tOptionValue * pPrevVal,
 tOptionValue const *
 optionGetValue(tOptionValue const * oov, char const * vname)
 {
-    tArgList *     arg_list;
-    tOptionValue * res = NULL;
+    tArgList *           arg_list;
+    const tOptionValue * res = NULL;
 
     if ((oov == NULL) || (oov->valType != OPARG_TYPE_HIERARCHY)) {
         errno = EINVAL;
@@ -325,14 +325,14 @@ optionGetValue(tOptionValue const * oov, char const * vname)
     arg_list = oov->v.nestVal;
 
     if (arg_list->useCt > 0) {
-        int     ct     = arg_list->useCt;
-        void ** ovlist = (void **)(arg_list->apzArgs);
+        int           ct     = arg_list->useCt;
+        const void ** ovlist = VOIDP(arg_list->apzArgs);
 
         if (vname == NULL) {
-            res = (tOptionValue *)*ovlist;
+            res = (const tOptionValue *)*ovlist;
 
         } else do {
-            tOptionValue * opt_val = *(ovlist++);
+            const tOptionValue * opt_val = *(ovlist++);
             if (strcmp(opt_val->pzName, vname) == 0) {
                 res = opt_val;
                 break;
@@ -374,9 +374,9 @@ optionGetValue(tOptionValue const * oov, char const * vname)
 tOptionValue const *
 optionNextValue(tOptionValue const * ov_list,tOptionValue const * oov )
 {
-    tArgList *     arg_list;
-    tOptionValue * res = NULL;
-    int            err = EINVAL;
+    tArgList *           arg_list;
+    const tOptionValue * res = NULL;
+    int                  err = EINVAL;
 
     if ((ov_list == NULL) || (ov_list->valType != OPARG_TYPE_HIERARCHY)) {
         errno = EINVAL;
@@ -384,18 +384,18 @@ optionNextValue(tOptionValue const * ov_list,tOptionValue const * oov )
     }
     arg_list = ov_list->v.nestVal;
     {
-        int     ct    = arg_list->useCt;
-        void ** o_list = (void **)(arg_list->apzArgs);
+        int           ct     = arg_list->useCt;
+        const void ** o_list = VOIDP(arg_list->apzArgs);
 
         while (ct-- > 0) {
-            tOptionValue * nov = *(o_list++);
+            const tOptionValue * nov = *(o_list++);
             if (nov == oov) {
                 if (ct == 0) {
                     err = ENOENT;
 
                 } else {
                     err = 0;
-                    res = (tOptionValue *)*o_list;
+                    res = (const tOptionValue *)*o_list;
                 }
                 break;
             }
index 3345558bec72e1015ad4f711d274d11b563f3588..e9bba83644cb0c8692a6e01e4d7671189594c71e 100644 (file)
@@ -189,12 +189,12 @@ find_name(char const * name, tOptions * pOpts, tOptDesc * pOD,
      *  The result gets stashed in a char * pointer.
      */
     uintptr_t   res = name_ct;
-    size_t      len = strlen((char *)name);
+    size_t      len = strlen(name);
     uintptr_t   idx;
 
     if (IS_DEC_DIGIT_CHAR(*name)) {
-        char * pz = VOIDP(name);
-        unsigned long val = strtoul(pz, &pz, 0);
+        char * pz;
+        unsigned long val = strtoul(name, &pz, 0);
         if ((*pz == NUL) && (val < name_ct))
             return (uintptr_t)val;
         pz_enum_err_fmt = znum_too_large;
@@ -215,7 +215,7 @@ find_name(char const * name, tOptions * pOpts, tOptDesc * pOD,
      *  Multiple partial matches means we have an ambiguous match.
      */
     for (idx = 0; idx < name_ct; idx++) {
-        if (strncmp((char *)paz_names[idx], (char *)name, len) == 0) {
+        if (strncmp(paz_names[idx], name, len) == 0) {
             if (paz_names[idx][len] == NUL)
                 return idx;  /* full match */
 
@@ -500,7 +500,7 @@ find_member_bit(tOptions * opts, tOptDesc * od, char const * pz, int len,
         if (shift_ct >= nm_ct)
             return 0UL;
 
-        return 1UL << shift_ct;
+        return (uintptr_t)1U << shift_ct;
     }
 }
 
index 90591cc9243dc5cfb294e16bb922ebefb14378c0..97a24df47216ce5bf0b13f6b9915810d1d1a209e 100644 (file)
@@ -80,7 +80,7 @@ parse_opt(char const ** nm_pp, char ** arg_pp, char * buf, size_t bufsz)
 
             buf[res] = NUL;
             *nm_pp   = buf;
-            *arg_pp  = (char *)p;
+            *arg_pp  = VOIDP(p);
             return res;
 
         default:
index e02e1e1b9bc797b69908c420238c80aa3a4ce0c7..81d4eee32d0c9ca981d7e8ae8c047ce173d63a02 100644 (file)
@@ -97,15 +97,14 @@ validate_struct(tOptions * opts, char const * pname)
      */
     if (opts->pzProgName == NULL) {
         char const *  pz = strrchr(pname, DIRCH);
-        char const ** pp =
-            (char const **)(void **)&(opts->pzProgName);
+        char const ** pp = VOIDP(&(opts->pzProgName));
 
         if (pz != NULL)
             *pp = pz+1;
         else
             *pp = pname;
 
-        pz = pathfind(getenv("PATH"), (char *)pname, "rx");
+        pz = pathfind(getenv("PATH"), pname, "rx");
         if (pz != NULL)
             pname = VOIDP(pz);
 
index b5230afd382a2b0bb04ed6a7c745fda249206cd0..ccda5b4e870dc358a187198582baa2ffaaa30d15 100644 (file)
@@ -225,7 +225,7 @@ add_prog_path(char * buf, int b_sz, char const * fname, char const * prg_path)
     if (strchr(prg_path, DIRCH) != NULL)
         path = prg_path;
     else {
-        path = pathfind(getenv("PATH"), (char *)prg_path, "rx");
+        path = pathfind(getenv("PATH"), prg_path, "rx");
 
         if (path == NULL)
             return false;
index a61df422c857c7b3e4e8ae818e25cf56d04df71f..fbe8e171de0d322916c4d2f20f178e2b2a05297d 100644 (file)
@@ -401,7 +401,7 @@ emit_usage(tOptions * opts)
 
         /* Copy the program name into the time/name buffer */
         for (;;) {
-            if ((*pzPN++ = (char)tolower(*pz++)) == NUL)
+            if ((*pzPN++ = (char)tolower((unsigned char)*pz++)) == NUL)
                 break;
         }
 
@@ -671,8 +671,8 @@ emit_match_expr(char const * name, tOptDesc * cod, tOptions * opts)
                 continue;
 
             match_ct = 0;
-            while (  toupper(od->pz_DisableName[match_ct])
-                  == toupper(name[match_ct]))
+            while (  toupper((unsigned char)od->pz_DisableName[match_ct])
+                  == toupper((unsigned char)name[match_ct]))
                 match_ct++;
             if (match_ct > min_match_ct)
                 min_match_ct = match_ct;
index f4fb22620932fe9710a0708308b5d34def7a0a45..aaf089f543d889e1a02c9158cf69bd3becb003a4 100644 (file)
@@ -859,6 +859,7 @@ LOCAL int
 get_special_char(char const ** ppz, int * ct)
 {
     char const * pz = *ppz;
+    char *       rz;
 
     if (*ct < 3)
         return '&';
@@ -872,7 +873,8 @@ get_special_char(char const ** ppz, int * ct)
             base = 16;
             pz++;
         }
-        retch = (int)strtoul(pz, (char **)&pz, base);
+        retch = (int)strtoul(pz, &rz, base);
+        pz = rz;
         if (*pz != ';')
             return '&';
         base = (int)(++pz - *ppz);
index e072b7d567f54313272aa582040641ce7b426b91..11e3d828d8975ef9da1ee9e3d05fc5a70cf7aee2 100644 (file)
@@ -60,14 +60,20 @@ typedef enum {
 static unsigned long
 str_const_to_ul (cch_t * str, cch_t ** ppz, int base)
 {
-  return strtoul (str, (char **)ppz, base);
+  char * pz;
+  int rv = strtoul (str, &pz, base);
+  *ppz = pz;
+  return rv;
 }
 
 /* Wrapper around strtol that does not require a cast.  */
 static long
 str_const_to_l (cch_t * str, cch_t ** ppz, int base)
 {
-  return strtol (str, (char **)ppz, base);
+  char * pz;
+  int rv = strtol (str, &pz, base);
+  *ppz = pz;
+  return rv;
 }
 
 /* Returns BASE + VAL * SCALE, interpreting BASE = BAD_TIME
index 6ca2c05229db400569515f405f846f78f2fd50a2..97ecb52e242532a6c0dda4b72f7097dfbd06d9ab 100644 (file)
@@ -113,7 +113,7 @@ optionResetOpt(tOptions * pOpts, tOptDesc * pOD)
             assert(0 == 1);
         }
     } else {
-        succ = opt_find_long(pOpts, (char *)pzArg, &opt_state);
+        succ = opt_find_long(pOpts, pzArg, &opt_state);
         if (! SUCCESSFUL(succ)) {
             fprintf(stderr, zIllOptStr, pOpts->pzProgPath, pzArg);
             pOpts->pUsageProc(pOpts, EXIT_FAILURE);
index f462ced8c65df0d6754421ef8e88cc596150d3be..cdab05f628ec064e5e0aa15d82850ecdf0f03226 100644 (file)
@@ -453,7 +453,7 @@ prt_val_list(FILE * fp, char const * name, tArgList * al)
     if (al == NULL)
         return;
     opt_ct   = al->useCt;
-    opt_list = (void **)al->apzArgs;
+    opt_list = VOIDP(al->apzArgs);
 
     if (opt_ct <= 0) {
         fprintf(fp, OPEN_CLOSE_FMT, name);
@@ -488,7 +488,7 @@ prt_nested(FILE * fp, tOptDesc * p)
         return;
 
     opt_ct   = al->useCt;
-    opt_list = (void **)al->apzArgs;
+    opt_list = VOIDP(al->apzArgs);
 
     if (opt_ct <= 0)
         return;
index cbff7fba47df59eddc41fccbd896bce4ab58a3c3..25550eaafeeae7eb80704032c75cb0ad285d7ad3 100644 (file)
@@ -57,7 +57,7 @@ copy_cooked(ch_t ** ppDest, char const ** ppSrc)
         case NUL:   *ppSrc = NULL; return;
         case '"':   goto done;
         case '\\':
-            pSrc += ao_string_cook_escape_char((char *)pSrc, (char *)&ch, 0x7F);
+            pSrc += ao_string_cook_escape_char((const char *)pSrc, (char *)&ch, 0x7F);
             if (ch == 0x7F)
                 break;
             /* FALLTHROUGH */