From: Juergen Perlinger Date: Sat, 5 Dec 2015 20:28:19 +0000 (+0000) Subject: [Bug 2980] reduce number of warnings X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2e9658b34d69fb416b35b43c255b15a0d818fa8;p=thirdparty%2Fntp.git [Bug 2980] reduce number of warnings - 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 --- diff --git a/ChangeLog b/ChangeLog index b4a8ab765..afa932c50 100644 --- 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. diff --git a/include/parse.h b/include/parse.h index 9b1ffb227..02dbb3021 100644 --- a/include/parse.h +++ b/include/parse.h @@ -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 diff --git a/ntpd/ntp_config.c b/ntpd/ntp_config.c index 1c754bd16..8b3483202 100644 --- a/ntpd/ntp_config.c +++ b/ntpd/ntp_config.c @@ -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 diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index dd23459df..05ab48bee 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -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; diff --git a/ntpd/ntp_scanner.c b/ntpd/ntp_scanner.c index 49adf6bfb..631c218b1 100644 --- a/ntpd/ntp_scanner.c +++ b/ntpd/ntp_scanner.c @@ -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; diff --git a/ntpd/ntp_timer.c b/ntpd/ntp_timer.c index 03084a353..55570958b 100644 --- a/ntpd/ntp_timer.c +++ b/ntpd/ntp_timer.c @@ -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; } } diff --git a/ntpd/refclock_chu.c b/ntpd/refclock_chu.c index 1f02a1c1f..d745c8167 100644 --- a/ntpd/refclock_chu.c +++ b/ntpd/refclock_chu.c @@ -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); diff --git a/ntpd/refclock_gpsdjson.c b/ntpd/refclock_gpsdjson.c index c2bf09a80..24a15e7f6 100644 --- a/ntpd/refclock_gpsdjson.c +++ b/ntpd/refclock_gpsdjson.c @@ -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); diff --git a/ntpd/refclock_jjy.c b/ntpd/refclock_jjy.c index fef829ca0..fc51fd9ee 100644 --- a/ntpd/refclock_jjy.c +++ b/ntpd/refclock_jjy.c @@ -149,8 +149,8 @@ */ 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( "", 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 : diff --git a/ntpd/refclock_shm.c b/ntpd/refclock_shm.c index f3e7f519d..f031a395c 100644 --- a/ntpd/refclock_shm.c +++ b/ntpd/refclock_shm.c @@ -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; diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index 438c7ca58..9e84aaf96 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -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; diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 5b3c9cb80..fa2f648fa 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -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; +} diff --git a/sntp/libopts/configfile.c b/sntp/libopts/configfile.c index 03156ca6d..8244371e5 100644 --- a/sntp/libopts/configfile.c +++ b/sntp/libopts/configfile.c @@ -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; } diff --git a/sntp/libopts/enum.c b/sntp/libopts/enum.c index 3345558be..e9bba8364 100644 --- a/sntp/libopts/enum.c +++ b/sntp/libopts/enum.c @@ -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; } } diff --git a/sntp/libopts/find.c b/sntp/libopts/find.c index 90591cc92..97a24df47 100644 --- a/sntp/libopts/find.c +++ b/sntp/libopts/find.c @@ -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: diff --git a/sntp/libopts/init.c b/sntp/libopts/init.c index e02e1e1b9..81d4eee32 100644 --- a/sntp/libopts/init.c +++ b/sntp/libopts/init.c @@ -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); diff --git a/sntp/libopts/load.c b/sntp/libopts/load.c index b5230afd3..ccda5b4e8 100644 --- a/sntp/libopts/load.c +++ b/sntp/libopts/load.c @@ -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; diff --git a/sntp/libopts/makeshell.c b/sntp/libopts/makeshell.c index a61df422c..fbe8e171d 100644 --- a/sntp/libopts/makeshell.c +++ b/sntp/libopts/makeshell.c @@ -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; diff --git a/sntp/libopts/nested.c b/sntp/libopts/nested.c index f4fb22620..aaf089f54 100644 --- a/sntp/libopts/nested.c +++ b/sntp/libopts/nested.c @@ -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); diff --git a/sntp/libopts/parse-duration.c b/sntp/libopts/parse-duration.c index e072b7d56..11e3d828d 100644 --- a/sntp/libopts/parse-duration.c +++ b/sntp/libopts/parse-duration.c @@ -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 diff --git a/sntp/libopts/reset.c b/sntp/libopts/reset.c index 6ca2c0522..97ecb52e2 100644 --- a/sntp/libopts/reset.c +++ b/sntp/libopts/reset.c @@ -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); diff --git a/sntp/libopts/save.c b/sntp/libopts/save.c index f462ced8c..cdab05f62 100644 --- a/sntp/libopts/save.c +++ b/sntp/libopts/save.c @@ -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; diff --git a/sntp/libopts/tokenize.c b/sntp/libopts/tokenize.c index cbff7fba4..25550eaaf 100644 --- a/sntp/libopts/tokenize.c +++ b/sntp/libopts/tokenize.c @@ -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 */