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.
/*
* 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
#include "ntp_parser.h"
#include "ntpd-opts.h"
+extern int yyparse(void);
+
/* Bug 2817 */
#if defined(HAVE_SYS_MMAN_H)
# include <sys/mman.h>
/* 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;
yylex(void)
{
static follby followedby = FOLLBY_TOKEN;
- int i;
+ size_t i;
int instring;
int yylval_was_set;
int converted;
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;
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;
}
}
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);
* 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";
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
++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;
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;
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);
*/
struct jjyRawDataBreak {
- char *pString ;
- int iLength ;
+ const char * pString ;
+ int iLength ;
} ;
#define MAX_TIMESTAMP 6
#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] ) ;
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 ++ ;
}
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 */
struct refclockproc *pp ;
struct jjyunit *up ;
- const char *pCmd ;
- int iCmdLen ;
+ const char * pCmd ;
+ int iCmdLen ;
pp = peer->procptr;
up = pp->unitptr ;
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 */
struct refclockproc *pp ;
struct jjyunit *up ;
- const char *pCmd ;
- int iCmdLen ;
+ const char * pCmd ;
+ int iCmdLen ;
pp = peer->procptr ;
up = pp->unitptr ;
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 },
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." ) ;
}
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 ;
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" ) ;
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" ) ;
teljjy_conn_silent ( struct peer *peer, struct refclockproc *pp, struct jjyunit *up )
{
- const char *pCmd ;
+ const char * pCmd ;
DEBUG_TELJJY_PRINTF( "teljjy_conn_silent" ) ;
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 },
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" ) ;
}
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 :
}
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 :
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" ) ;
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" ) ;
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 :
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;
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;
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
{
char *list;
- char *msg, *fmt;
+ char *msg;
list = list_digest_names();
for (icmd = 0; icmd < sizeof(builtins)/sizeof(builtins[0]); icmd++) {
#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);
}
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;
+}
}
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;
}
if (name == NULL) {
- res = (tOptionValue *)*poptv;
+ res = (const tOptionValue *)*poptv;
break;
}
char const * pzName, char const * pzVal)
{
bool old_found = false;
- tOptionValue * res = NULL;
+ const tOptionValue * res = NULL;
(void)pzName;
(void)pzVal;
}
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;
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;
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;
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;
}
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;
}
* 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;
* 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 */
if (shift_ct >= nm_ct)
return 0UL;
- return 1UL << shift_ct;
+ return (uintptr_t)1U << shift_ct;
}
}
buf[res] = NUL;
*nm_pp = buf;
- *arg_pp = (char *)p;
+ *arg_pp = VOIDP(p);
return res;
default:
*/
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);
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;
/* 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;
}
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;
get_special_char(char const ** ppz, int * ct)
{
char const * pz = *ppz;
+ char * rz;
if (*ct < 3)
return '&';
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);
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
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);
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);
return;
opt_ct = al->useCt;
- opt_list = (void **)al->apzArgs;
+ opt_list = VOIDP(al->apzArgs);
if (opt_ct <= 0)
return;
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 */