From: Harlan Stenn Date: Mon, 29 Dec 2014 06:39:40 +0000 (+0000) Subject: [Bug 2713] variable type/cast, parameter name, general cleanup from NetBSD X-Git-Tag: NTP_4_2_8P1_BETA3~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed0d19521e48882c58cfa564114fc678133a9bff;p=thirdparty%2Fntp.git [Bug 2713] variable type/cast, parameter name, general cleanup from NetBSD bk: 54a0f72cwK08labRiyqs390lgYO5GQ --- diff --git a/ChangeLog b/ChangeLog index e64650d48..9a90f3f1f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ --- + +* [Bug 2713] variable type/cast, parameter name, general cleanup from NetBSD. +--- (4.2.8p1-beta2) 2014/12/27 Released by Harlan Stenn * [Bug 2674] Install sntp in sbin on NetBSD. diff --git a/include/audio.h b/include/audio.h index 1b969bd49..0d7422666 100644 --- a/include/audio.h +++ b/include/audio.h @@ -9,6 +9,6 @@ /* * Function prototypes */ -int audio_init (char *, int, int); +int audio_init (const char *, int, int); int audio_gain (int, int, int); void audio_show (void); diff --git a/include/icom.h b/include/icom.h index 66d12e51f..b271afbec 100644 --- a/include/icom.h +++ b/include/icom.h @@ -83,5 +83,5 @@ /* * Function prototypes */ -int icom_init (char *, int, int); +int icom_init (const char *, int, int); int icom_freq (int, int, double); diff --git a/include/ntp_config.h b/include/ntp_config.h index 900688cef..a74cd552b 100644 --- a/include/ntp_config.h +++ b/include/ntp_config.h @@ -239,6 +239,7 @@ struct config_tree_tag { int_fifo * reset_counters; sim_fifo * sim_details; + int mdnstries; }; @@ -286,7 +287,7 @@ attr_val *create_attr_dval(int attr, double value); attr_val *create_attr_ival(int attr, int value); attr_val *create_attr_uval(int attr, u_int value); attr_val *create_attr_rangeval(int attr, int first, int last); -attr_val *create_attr_sval(int attr, char *s); +attr_val *create_attr_sval(int attr, const char *s); filegen_node *create_filegen_node(int filegen_token, attr_val_fifo *options); string_node *create_string_node(char *str); @@ -316,7 +317,7 @@ int dump_all_config_trees(FILE *df, int comment); #endif #if defined(HAVE_SETRLIMIT) -void ntp_rlimit(int, rlim_t, int, char *); +void ntp_rlimit(int, rlim_t, int, const char *); #endif #endif /* !defined(NTP_CONFIG_H) */ diff --git a/include/ntp_filegen.h b/include/ntp_filegen.h index f5ba8afe9..549bedbc8 100644 --- a/include/ntp_filegen.h +++ b/include/ntp_filegen.h @@ -52,5 +52,5 @@ extern void filegen_statsdir(void); extern FILEGEN *filegen_get (const char *); extern void filegen_register (const char *, const char *, FILEGEN *); #ifdef DEBUG -extern void filegen_unregister(char *); +extern void filegen_unregister(const char *); #endif diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h index 7c884fc32..38180f0d7 100644 --- a/include/ntp_stdlib.h +++ b/include/ntp_stdlib.h @@ -96,14 +96,14 @@ extern int ymd2yd (int, int, int); /* a_md5encrypt.c */ extern int MD5authdecrypt (int, u_char *, u_int32 *, int, int); extern int MD5authencrypt (int, u_char *, u_int32 *, int); -extern void MD5auth_setkey (keyid_t, int, const u_char *, int); +extern void MD5auth_setkey (keyid_t, int, const u_char *, size_t); extern u_int32 addr2refid (sockaddr_u *); /* emalloc.c */ #ifndef EREALLOC_CALLSITE /* ntp_malloc.h defines */ extern void * ereallocz (void *, size_t, size_t, int); #define erealloczsite(p, n, o, z, f, l) ereallocz(p, n, o, (z)) -extern void * emalloc (size_t); +#define emalloc(n) ereallocz(NULL, n, 0, FALSE) #define emalloc_zero(c) ereallocz(NULL, (c), 0, TRUE) #define erealloc(p, c) ereallocz(p, (c), 0, FALSE) #define erealloc_zero(p, n, o) ereallocz(p, n, (o), TRUE) @@ -129,11 +129,11 @@ extern char * estrdup_impl (const char *, const char *, int); extern int atoint (const char *, long *); extern int atouint (const char *, u_long *); extern int hextoint (const char *, u_long *); -extern char * humanlogtime (void); -extern char * humantime (time_t); +extern const char * humanlogtime (void); +extern const char * humantime (time_t); extern char * mfptoa (u_int32, u_int32, short); extern char * mfptoms (u_int32, u_int32, short); -extern const char * modetoa (int); +extern const char * modetoa (size_t); extern const char * eventstr (int); extern const char * ceventstr (int); extern const char * res_match_flags(u_short); diff --git a/include/ntpd.h b/include/ntpd.h index 51d8f2acc..77fe4843a 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -78,7 +78,7 @@ extern int mprintf_event (int, struct peer *, const char *, ...) struct ctl_var { u_short code; u_short flags; - char *text; + const char *text; }; /* * Flag values @@ -218,7 +218,7 @@ extern struct value tai_leap; /* ntp_proto.c */ extern void transmit (struct peer *); extern void receive (struct recvbuf *); -extern void peer_clear (struct peer *, char *); +extern void peer_clear (struct peer *, const char *); extern void process_packet (struct peer *, struct pkt *, u_int); extern void clock_select (void); @@ -285,7 +285,7 @@ extern void record_loop_stats (double, double, double, double, int); extern void record_clock_stats (sockaddr_u *, const char *); extern int mprintf_clock_stats(sockaddr_u *, const char *, ...) NTP_PRINTF(2, 3); -extern void record_raw_stats (sockaddr_u *srcadr, sockaddr_u *dstadr, l_fp *t1, l_fp *t2, l_fp *t3, l_fp *t4, int leap, int version, int mode, int stratum, int poll, int precision, double root_delay, double root_dispersion, u_int32 refid); +extern void record_raw_stats (sockaddr_u *srcadr, sockaddr_u *dstadr, l_fp *t1, l_fp *t2, l_fp *t3, l_fp *t4, int leap, int version, int mode, int stratum, int ppoll, int precision, double root_delay, double root_dispersion, u_int32 refid); extern void check_leap_file (int is_daily_check, u_int32 ntptime, const time_t * systime); extern void record_crypto_stats (sockaddr_u *, const char *); #ifdef DEBUG diff --git a/lib/isc/backtrace.c b/lib/isc/backtrace.c index d2f044cb8..4274da31b 100644 --- a/lib/isc/backtrace.c +++ b/lib/isc/backtrace.c @@ -211,17 +211,17 @@ isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) { #endif isc_result_t -isc_backtrace_getsymbolfromindex(int index, const void **addrp, +isc_backtrace_getsymbolfromindex(int idx, const void **addrp, const char **symbolp) { REQUIRE(addrp != NULL && *addrp == NULL); REQUIRE(symbolp != NULL && *symbolp == NULL); - if (index < 0 || index >= isc__backtrace_nsymbols) + if (idx < 0 || idx >= isc__backtrace_nsymbols) return (ISC_R_RANGE); - *addrp = isc__backtrace_symtable[index].addr; - *symbolp = isc__backtrace_symtable[index].symbol; + *addrp = isc__backtrace_symtable[idx].addr; + *symbolp = isc__backtrace_symtable[idx].symbol; return (ISC_R_SUCCESS); } diff --git a/lib/isc/event.c b/lib/isc/event.c index 8ab75240d..e97961682 100644 --- a/lib/isc/event.c +++ b/lib/isc/event.c @@ -34,9 +34,7 @@ static void destroy(isc_event_t *event) { - isc_mem_t *mctx = event->ev_destroy_arg; - - isc_mem_put(mctx, event, event->ev_size); + isc_mem_put(event->ev_destroy_arg, event, event->ev_size); } isc_event_t * diff --git a/lib/isc/include/isc/backtrace.h b/lib/isc/include/isc/backtrace.h index c0e98c0b7..7d7fc3217 100644 --- a/lib/isc/include/isc/backtrace.h +++ b/lib/isc/include/isc/backtrace.h @@ -85,12 +85,12 @@ isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes); */ isc_result_t -isc_backtrace_getsymbolfromindex(int index, const void **addrp, +isc_backtrace_getsymbolfromindex(int idx, const void **addrp, const char **symbolp); /*%< * Returns the content of the internal symbol table of the given index. * On success, *addrsp and *symbolp point to the address and the symbol of - * the 'index'th entry of the table, respectively. If 'index' is not in the + * the 'index'th entry of the table, respectively. If 'idx' is not in the * range of the symbol table, ISC_R_RANGE will be returned. * * Requires diff --git a/lib/isc/include/isc/socket.h b/lib/isc/include/isc/socket.h index 38f6f7802..46e05a077 100644 --- a/lib/isc/include/isc/socket.h +++ b/lib/isc/include/isc/socket.h @@ -274,7 +274,7 @@ typedef struct isc_socketmgrmethods { } isc_socketmgrmethods_t; typedef struct isc_socketmethods { - void (*attach)(isc_socket_t *socket, + void (*attach)(isc_socket_t *sock, isc_socket_t **socketp); void (*detach)(isc_socket_t **socketp); isc_result_t (*bind)(isc_socket_t *sock, isc_sockaddr_t *sockaddr, @@ -296,9 +296,9 @@ typedef struct isc_socketmethods { isc_sockettype_t (*gettype)(isc_socket_t *sock); void (*ipv6only)(isc_socket_t *sock, isc_boolean_t yes); isc_result_t (*fdwatchpoke)(isc_socket_t *sock, int flags); - isc_result_t (*dup)(isc_socket_t *socket, + isc_result_t (*dup)(isc_socket_t *sock, isc_socket_t **socketp); - int (*getfd)(isc_socket_t *socket); + int (*getfd)(isc_socket_t *sock); } isc_socketmethods_t; /*% @@ -1094,24 +1094,24 @@ isc_socket_permunix(isc_sockaddr_t *sockaddr, isc_uint32_t perm, * \li #ISC_R_FAILURE */ -void isc_socket_setname(isc_socket_t *socket, const char *name, void *tag); +void isc_socket_setname(isc_socket_t *sock, const char *name, void *tag); /*%< * Set the name and optional tag for a socket. This allows tracking of the * owner or purpose for this socket, and is useful for tracing and statistics * reporting. */ -const char *isc_socket_getname(isc_socket_t *socket); +const char *isc_socket_getname(isc_socket_t *sock); /*%< * Get the name associated with a socket, if any. */ -void *isc_socket_gettag(isc_socket_t *socket); +void *isc_socket_gettag(isc_socket_t *sock); /*%< * Get the tag associated with a socket, if any. */ -int isc_socket_getfd(isc_socket_t *socket); +int isc_socket_getfd(isc_socket_t *sock); /*%< * Get the file descriptor associated with a socket */ diff --git a/lib/isc/log.c b/lib/isc/log.c index 0c142ce77..ce98303fe 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -1521,10 +1521,11 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, level_string[0] == '\0') { if (level < ISC_LOG_CRITICAL) snprintf(level_string, sizeof(level_string), + "%s %d: ", isc_msgcat_get(isc_msgcat, ISC_MSGSET_LOG, ISC_MSG_LEVEL, - "level %d: "), + "level"), level); else if (level > ISC_LOG_DYNAMIC) snprintf(level_string, sizeof(level_string), diff --git a/lib/isc/netaddr.c b/lib/isc/netaddr.c index d6928c10d..457576b77 100644 --- a/lib/isc/netaddr.c +++ b/lib/isc/netaddr.c @@ -202,9 +202,10 @@ isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size) { if (result != ISC_R_SUCCESS) { snprintf(array, size, + "<%s %u>", isc_msgcat_get(isc_msgcat, ISC_MSGSET_NETADDR, ISC_MSG_UNKNOWNADDR, - ""), + "unknown address, family"), na->family); array[size - 1] = '\0'; } diff --git a/lib/isc/sockaddr.c b/lib/isc/sockaddr.c index 2a7268f96..1ae5e7c91 100644 --- a/lib/isc/sockaddr.c +++ b/lib/isc/sockaddr.c @@ -192,9 +192,10 @@ isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size) { * The message is the same as in netaddr.c. */ snprintf(array, size, + "<%s %u>", isc_msgcat_get(isc_msgcat, ISC_MSGSET_NETADDR, ISC_MSG_UNKNOWNADDR, - ""), + "unknown address, family"), sa->type.sa.sa_family); array[size - 1] = '\0'; } @@ -230,10 +231,11 @@ isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, isc_boolean_t address_only) { break; default: UNEXPECTED_ERROR(__FILE__, __LINE__, + "%s: %d", isc_msgcat_get(isc_msgcat, ISC_MSGSET_SOCKADDR, ISC_MSG_UNKNOWNFAMILY, - "unknown address family: %d"), + "unknown address family"), (int)sockaddr->type.sa.sa_family); s = (const unsigned char *)&sockaddr->type; length = sockaddr->length; @@ -410,9 +412,10 @@ isc_sockaddr_setport(isc_sockaddr_t *sockaddr, in_port_t port) { break; default: FATAL_ERROR(__FILE__, __LINE__, + "%s: %d", isc_msgcat_get(isc_msgcat, ISC_MSGSET_SOCKADDR, ISC_MSG_UNKNOWNFAMILY, - "unknown address family: %d"), + "unknown address family"), (int)sockaddr->type.sa.sa_family); } } @@ -430,9 +433,10 @@ isc_sockaddr_getport(const isc_sockaddr_t *sockaddr) { break; default: FATAL_ERROR(__FILE__, __LINE__, + "%s: %d", isc_msgcat_get(isc_msgcat, ISC_MSGSET_SOCKADDR, ISC_MSG_UNKNOWNFAMILY, - "unknown address family: %d"), + "unknown address family"), (int)sockaddr->type.sa.sa_family); } diff --git a/lib/isc/unix/ifiter_getifaddrs.c b/lib/isc/unix/ifiter_getifaddrs.c index 547a83f07..c2e4044ac 100644 --- a/lib/isc/unix/ifiter_getifaddrs.c +++ b/lib/isc/unix/ifiter_getifaddrs.c @@ -96,9 +96,13 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) { } if (ret < 0) { isc__strerror(errno, strbuf, sizeof(strbuf)); - UNEXPECTED_ERROR(__FILE__, __LINE__, isc_msgcat_get(isc_msgcat, - ISC_MSGSET_IFITERGETIFADDRS, ISC_MSG_GETIFADDRS, - "getting interface addresses: getifaddrs: %s"), strbuf); + UNEXPECTED_ERROR(__FILE__, __LINE__, + "getting interface addresses: %s: %s", + isc_msgcat_get(isc_msgcat, + ISC_MSGSET_IFITERGETIFADDRS, + ISC_MSG_GETIFADDRS, + "getifaddrs"), + strbuf); result = ISC_R_UNEXPECTED; goto failure; } diff --git a/libjsmn/jsmn.c b/libjsmn/jsmn.c index bae1063d5..aa8b12b80 100644 --- a/libjsmn/jsmn.c +++ b/libjsmn/jsmn.c @@ -9,7 +9,7 @@ static jsmntok_t *jsmn_alloc_token(jsmn_parser *parser, jsmntok_t *tokens, size_t num_tokens) { jsmntok_t *tok; - if (parser->toknext >= num_tokens) { + if ((size_t)parser->toknext >= num_tokens) { return NULL; } tok = &tokens[parser->toknext++]; @@ -108,10 +108,10 @@ static jsmnerr_t jsmn_parse_string(jsmn_parser *parser, const char *js, /* Backslash: Quoted symbol expected */ if (c == '\\') { + int i = 0; + parser->pos++; switch (js[parser->pos]) { - int i = 0; - /* Allowed escaped symbols */ case '\"': case '/' : case '\\' : case 'b' : case 'f' : case 'r' : case 'n' : case 't' : diff --git a/libntp/atoint.c b/libntp/atoint.c index 1064b366a..9da8c13c3 100644 --- a/libntp/atoint.c +++ b/libntp/atoint.c @@ -35,7 +35,7 @@ atoint( u = 0; while (*cp != '\0') { - if (!isdigit((int)*cp)) + if (!isdigit((unsigned char)*cp)) return 0; if (u > 214748364 || (u == 214748364 && *cp > oflow_digit)) return 0; /* overflow */ diff --git a/libntp/atolfp.c b/libntp/atolfp.c index 4afeb23d3..3a65f6bcb 100644 --- a/libntp/atolfp.c +++ b/libntp/atolfp.c @@ -52,7 +52,7 @@ atolfp( * * [spaces][-|+][digits][.][digits][spaces|\n|\0] */ - while (isspace((int)*cp)) + while (isspace((unsigned char)*cp)) cp++; if (*cp == '-') { @@ -63,7 +63,7 @@ atolfp( if (*cp == '+') cp++; - if (*cp != '.' && !isdigit((int)*cp)) + if (*cp != '.' && !isdigit((unsigned char)*cp)) return 0; while (*cp != '\0' && (ind = strchr(digits, *cp)) != NULL) { @@ -72,7 +72,7 @@ atolfp( cp++; } - if (*cp != '\0' && !isspace((int)*cp)) { + if (*cp != '\0' && !isspace((unsigned char)*cp)) { if (*cp++ != '.') return 0; @@ -84,10 +84,10 @@ atolfp( cp++; } - while (isdigit((int)*cp)) + while (isdigit((unsigned char)*cp)) cp++; - if (*cp != '\0' && !isspace((int)*cp)) + if (*cp != '\0' && !isspace((unsigned char)*cp)) return 0; } diff --git a/libntp/atouint.c b/libntp/atouint.c index ab86130df..0a6163907 100644 --- a/libntp/atouint.c +++ b/libntp/atouint.c @@ -28,7 +28,7 @@ atouint( u = 0; while ('\0' != *cp) { - if (!isdigit(*cp)) + if (!isdigit((unsigned char)*cp)) return 0; if (u > 429496729 || (u == 429496729 && *cp >= '6')) return 0; /* overflow */ diff --git a/libntp/audio.c b/libntp/audio.c index 2a5661982..6f2262c99 100644 --- a/libntp/audio.c +++ b/libntp/audio.c @@ -67,7 +67,7 @@ static struct audio_info info; /* audio device info */ static int ctl_fd; /* audio control file descriptor */ #ifdef PCM_STYLE_SOUND -static void audio_config_read (int, char **, char **); +static void audio_config_read (int, const char **, const char **); static int mixer_name (const char *, int); @@ -114,8 +114,8 @@ mixer_name( static void audio_config_read( int unit, - char **c_dev, /* Control device */ - char **i_dev /* input device */ + const char **c_dev, /* Control device */ + const char **i_dev /* input device */ ) { FILE *fd; @@ -148,12 +148,12 @@ audio_config_read( /* Remove any trailing spaces */ for (i = strlen(line); - i > 0 && isascii((int)line[i - 1]) && isspace((int)line[i - 1]); + i > 0 && isascii((unsigned char)line[i - 1]) && isspace((unsigned char)line[i - 1]); ) line[--i] = '\0'; /* Remove leading space */ - for (cc = line; *cc && isascii((int)*cc) && isspace((int)*cc); cc++) + for (cc = line; *cc && isascii((unsigned char)*cc) && isspace((unsigned char)*cc); cc++) continue; /* Stop if nothing left */ @@ -162,16 +162,16 @@ audio_config_read( /* Uppercase the command and find the arg */ for (ca = cc; *ca; ca++) { - if (isascii((int)*ca)) { - if (islower((int)*ca)) { - *ca = toupper(*ca); - } else if (isspace((int)*ca) || (*ca == '=')) + if (isascii((unsigned char)*ca)) { + if (islower((unsigned char)*ca)) { + *ca = toupper((unsigned char)*ca); + } else if (isspace((unsigned char)*ca) || (*ca == '=')) break; } } /* Remove space (and possible =) leading the arg */ - for (; *ca && isascii((int)*ca) && (isspace((int)*ca) || (*ca == '=')); ca++) + for (; *ca && isascii((unsigned char)*ca) && (isspace((unsigned char)*ca) || (*ca == '=')); ca++) continue; if (!strncmp(cc, "IDEV", 4) && @@ -210,7 +210,7 @@ audio_config_read( */ int audio_init( - char *dname, /* device name */ + const char *dname, /* device name */ int bufsiz, /* buffer size */ int unit /* device unit (0-3) */ ) @@ -227,7 +227,7 @@ audio_init( #endif int fd; int rval; - char *actl = + const char *actl = #ifdef PCM_STYLE_SOUND actl_dev #else diff --git a/libntp/authkeys.c b/libntp/authkeys.c index 7b4427cd2..68771ffb3 100644 --- a/libntp/authkeys.c +++ b/libntp/authkeys.c @@ -517,7 +517,7 @@ MD5auth_setkey( keyid_t keyno, int keytype, const u_char *key, - int len + size_t len ) { symkey * sk; @@ -527,7 +527,6 @@ MD5auth_setkey( DEBUG_ENSURE(keytype <= USHRT_MAX); DEBUG_ENSURE(len < 4 * 1024); - len = max(0, len); /* * See if we already have the key. If so just stick in the * new value. diff --git a/libntp/authreadkeys.c b/libntp/authreadkeys.c index 9b02119d1..e8ddc942a 100644 --- a/libntp/authreadkeys.c +++ b/libntp/authreadkeys.c @@ -77,8 +77,8 @@ authreadkeys( int keytype; char buf[512]; /* lots of room for line */ u_char keystr[32]; /* Bug 2537 */ - int len; - int j; + size_t len; + size_t j; /* * Open file. Complain and return if it can't be opened. @@ -181,11 +181,11 @@ authreadkeys( char hex[] = "0123456789abcdef"; u_char temp; char *ptr; - int jlim; + size_t jlim; jlim = min(len, 2 * sizeof(keystr)); for (j = 0; j < jlim; j++) { - ptr = strchr(hex, tolower(token[j])); + ptr = strchr(hex, tolower((unsigned char)token[j])); if (ptr == NULL) break; /* abort decoding */ temp = (u_char)(ptr - hex); diff --git a/libntp/emalloc.c b/libntp/emalloc.c index c49c5c1e1..6c1c6787e 100644 --- a/libntp/emalloc.c +++ b/libntp/emalloc.c @@ -86,6 +86,7 @@ estrdup_impl( } +#if 0 #ifndef EREALLOC_CALLSITE void * emalloc(size_t newsz) @@ -93,4 +94,5 @@ emalloc(size_t newsz) return ereallocz(NULL, newsz, 0, FALSE); } #endif +#endif diff --git a/libntp/hextoint.c b/libntp/hextoint.c index d24b5a0bf..980a43f9d 100644 --- a/libntp/hextoint.c +++ b/libntp/hextoint.c @@ -23,7 +23,7 @@ hextoint( u = 0; while (*cp != '\0') { - if (!isxdigit(*cp)) + if (!isxdigit((unsigned char)*cp)) return 0; if (u & 0xF0000000) return 0; /* overflow */ diff --git a/libntp/hextolfp.c b/libntp/hextolfp.c index 8fbce2e5b..2bff929dc 100644 --- a/libntp/hextolfp.c +++ b/libntp/hextolfp.c @@ -30,7 +30,7 @@ hextolfp( * * [spaces]8_hex_digits[.]8_hex_digits[spaces|\n|\0] */ - while (isspace((int)*cp)) + while (isspace((unsigned char)*cp)) cp++; cpstart = cp; @@ -59,7 +59,7 @@ hextolfp( if ((cp - cpstart) < 8 || ind == NULL) return 0; - if (*cp != '\0' && !isspace((int)*cp)) + if (*cp != '\0' && !isspace((unsigned char)*cp)) return 0; lfp->l_ui = dec_i; diff --git a/libntp/humandate.c b/libntp/humandate.c index f88d8d24c..d9d5e89df 100644 --- a/libntp/humandate.c +++ b/libntp/humandate.c @@ -13,7 +13,7 @@ /* This is used in msyslog.c; we don't want to clutter up the log with the year and day of the week, etc.; just the minimal date and time. */ -char * +const char * humanlogtime(void) { char * bp; @@ -39,7 +39,7 @@ humanlogtime(void) * humantime() -- like humanlogtime() but without date, and with the * time to display given as an argument. */ -char * +const char * humantime( time_t cursec ) diff --git a/libntp/icom.c b/libntp/icom.c index c981d8548..807001142 100644 --- a/libntp/icom.c +++ b/libntp/icom.c @@ -121,17 +121,15 @@ doublefreq( /* returns void */ */ int icom_init( - char *device, /* device name/link */ + const char *device, /* device name/link */ int speed, /* line speed */ int trace /* trace flags */ ) { TTY ttyb; int fd; - int flags; int rc; int saved_errno; - flags = trace; fd = tty_open(device, O_RDWR, 0777); if (fd < 0) return -1; diff --git a/libntp/modetoa.c b/libntp/modetoa.c index b476bc9e9..6f13d2058 100644 --- a/libntp/modetoa.c +++ b/libntp/modetoa.c @@ -9,7 +9,7 @@ const char * modetoa( - int mode + size_t mode ) { char *bp; @@ -25,9 +25,9 @@ modetoa( "bclient", }; - if (mode < 0 || mode >= COUNTOF(modestrings)) { + if (mode >= COUNTOF(modestrings)) { LIB_GETBUF(bp); - snprintf(bp, LIB_BUFLENGTH, "mode#%d", mode); + snprintf(bp, LIB_BUFLENGTH, "mode#%zu", mode); return bp; } diff --git a/libntp/mstolfp.c b/libntp/mstolfp.c index 1a1a02b5f..828b14cfb 100644 --- a/libntp/mstolfp.c +++ b/libntp/mstolfp.c @@ -32,7 +32,7 @@ mstolfp( */ bp = buf; cp = str; - while (isspace((int)*cp)) + while (isspace((unsigned char)*cp)) cp++; if (*cp == '-') { @@ -40,7 +40,7 @@ mstolfp( cp++; } - if (*cp != '.' && !isdigit((int)*cp)) + if (*cp != '.' && !isdigit((unsigned char)*cp)) return 0; @@ -48,7 +48,7 @@ mstolfp( * Search forward for the decimal point or the end of the string. */ cpdec = cp; - while (isdigit((int)*cpdec)) + while (isdigit((unsigned char)*cpdec)) cpdec++; /* @@ -86,7 +86,7 @@ mstolfp( if (*cp == '.') { cp++; - while (isdigit((int)*cp)) + while (isdigit((unsigned char)*cp)) *bp++ = (char)*cp++; } *bp = '\0'; @@ -95,7 +95,7 @@ mstolfp( * Check to make sure the string is properly terminated. If * so, give the buffer to the decoding routine. */ - if (*cp != '\0' && !isspace((int)*cp)) + if (*cp != '\0' && !isspace((unsigned char)*cp)) return 0; return atolfp(buf, lfp); } diff --git a/libntp/ntp_calendar.c b/libntp/ntp_calendar.c index e557f4ec6..94ca0e9ee 100644 --- a/libntp/ntp_calendar.c +++ b/libntp/ntp_calendar.c @@ -153,7 +153,11 @@ ntpcal_get_build_date( * problem. * */ +#ifdef MKREPRO_DATE + static const char build[] = MKREPRO_TIME "/" MKREPRO_DATE; +#else static const char build[] = __TIME__ "/" __DATE__; +#endif static const char mlist[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; char monstr[4]; @@ -1561,7 +1565,7 @@ isocal_ntp64_to_date( id->year = (uint16_t)ds.hi + 1; /* shift to current */ id->week = (uint8_t )ds.lo + 1; - return (ds.hi >= 0 && ds.hi < 0xFFFFU); + return (ds.hi >= 0 && ds.hi < 0x0000FFFF); } int diff --git a/libntp/ntp_crypto_rnd.c b/libntp/ntp_crypto_rnd.c index 6cc8f5d7e..96348f2e8 100644 --- a/libntp/ntp_crypto_rnd.c +++ b/libntp/ntp_crypto_rnd.c @@ -22,9 +22,9 @@ #include int crypto_rand_init = 0; -#endif +#else -#ifndef HAVE_ARC4RANDOM_BUF +# ifndef HAVE_ARC4RANDOM_BUF static void arc4random_buf(void *buf, size_t nbytes); @@ -37,6 +37,7 @@ arc4random_buf(void *buf, size_t nbytes) evutil_secure_rng_get_bytes(buf, nbytes); return; } +# endif #endif /* @@ -100,6 +101,7 @@ ntp_crypto_random_buf( err = ERR_get_error(); err_str = ERR_error_string(err, NULL); /* XXX: Log the error */ + (void)&err_str; return -1; } diff --git a/libntp/ntp_intres.c b/libntp/ntp_intres.c index 2ac70c1a4..eea88a127 100644 --- a/libntp/ntp_intres.c +++ b/libntp/ntp_intres.c @@ -684,11 +684,11 @@ blocking_getnameinfo( blocking_gni_resp * gni_resp; size_t octets; size_t resp_octets; - char * host; char * service; char * cp; int rc; time_t time_now; + char host[1024]; gni_req = (void *)((char *)req + sizeof(*req)); @@ -699,19 +699,7 @@ blocking_getnameinfo( * large allocations. We only need room for the host * and service names. */ - NTP_REQUIRE(octets < 1024); - -#ifndef HAVE_ALLOCA - host = emalloc(octets); -#else - host = alloca(octets); - if (NULL == host) { - msyslog(LOG_ERR, - "blocking_getnameinfo unable to allocate %lu octets on stack", - (u_long)octets); - exit(1); - } -#endif + NTP_REQUIRE(octets < sizeof(host)); service = host + gni_req->hostoctets; worker_ctx = get_worker_context(c, gni_req->dns_idx); @@ -793,9 +781,6 @@ blocking_getnameinfo( rc = queue_blocking_response(c, resp, resp_octets, req); if (rc) msyslog(LOG_ERR, "blocking_getnameinfo unable to queue response"); -#ifndef HAVE_ALLOCA - free(host); -#endif return rc; } diff --git a/libntp/ntp_lineedit.c b/libntp/ntp_lineedit.c index c5aad3108..e3bc0022a 100644 --- a/libntp/ntp_lineedit.c +++ b/libntp/ntp_lineedit.c @@ -178,23 +178,22 @@ ntp_readline( if (NULL != line) { if (*line) { add_history(line); - *pcount = strlen(line); - } else { - free(line); - line = NULL; } + *pcount = strlen(line); } #endif /* LE_READLINE */ #ifdef LE_EDITLINE cline = el_gets(ntp_el, pcount); - if (NULL != cline && *cline) { + if (NULL != cline) { history(ntp_hist, &hev, H_ENTER, cline); - *pcount = strlen(cline); line = estrdup(cline); - } else + } else if (*pcount == -1) { line = NULL; + } else { + line = estrdup(""); + } #endif /* LE_EDITLINE */ #ifdef LE_NONE diff --git a/libntp/octtoint.c b/libntp/octtoint.c index d189e40c4..e519601d0 100644 --- a/libntp/octtoint.c +++ b/libntp/octtoint.c @@ -24,7 +24,7 @@ octtoint( u = 0; while (*cp != '\0') { - if (!isdigit((int)*cp) || *cp == '8' || *cp == '9') + if (!isdigit((unsigned char)*cp) || *cp == '8' || *cp == '9') return 0; if (u >= 0x20000000) return 0; /* overflow */ diff --git a/libntp/prettydate.c b/libntp/prettydate.c index f12129716..5da5ecc50 100644 --- a/libntp/prettydate.c +++ b/libntp/prettydate.c @@ -133,7 +133,7 @@ get_struct_tm( if (--folds < MINFOLD) return NULL; ts += SOLAR_CYCLE_SECS; - } else if (ts >= SOLAR_CYCLE_SECS) { + } else if (ts >= (time_t)SOLAR_CYCLE_SECS) { if (++folds > MAXFOLD) return NULL; ts -= SOLAR_CYCLE_SECS; @@ -157,10 +157,10 @@ common_prettydate( int local ) { - static const char* pfmt[2] = { - "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03u", - "%08lx.%08lx [%s, %s %2d %4d %2d:%02d:%02d.%03u UTC]" - }; + static const char pfmt0[] = + "%08lx.%08lx %s, %s %2d %4d %2d:%02d:%02d.%03u"; + static const char pfmt1[] = + "%08lx.%08lx [%s, %s %2d %4d %2d:%02d:%02d.%03u UTC]"; char *bp; struct tm *tm; @@ -186,13 +186,13 @@ common_prettydate( */ struct calendar jd; ntpcal_time_to_date(&jd, &sec); - snprintf(bp, LIB_BUFLENGTH, pfmt[local != 0], + snprintf(bp, LIB_BUFLENGTH, local ? pfmt1 : pfmt0, (u_long)ts->l_ui, (u_long)ts->l_uf, daynames[jd.weekday], months[jd.month-1], jd.monthday, jd.year, jd.hour, jd.minute, jd.second, msec); } else - snprintf(bp, LIB_BUFLENGTH, pfmt[0], + snprintf(bp, LIB_BUFLENGTH, pfmt0, (u_long)ts->l_ui, (u_long)ts->l_uf, daynames[tm->tm_wday], months[tm->tm_mon], tm->tm_mday, 1900 + tm->tm_year, tm->tm_hour, diff --git a/libntp/ssl_init.c b/libntp/ssl_init.c index 7f1e9a096..a9d1d546d 100644 --- a/libntp/ssl_init.c +++ b/libntp/ssl_init.c @@ -96,13 +96,13 @@ keytype_from_text( LIB_GETBUF(upcased); strlcpy(upcased, text, LIB_BUFLENGTH); for (pch = upcased; '\0' != *pch; pch++) - *pch = (char)toupper(*pch); + *pch = (char)toupper((unsigned char)*pch); key_type = OBJ_sn2nid(upcased); #else key_type = 0; #endif - if (!key_type && 'm' == tolower(text[0])) + if (!key_type && 'm' == tolower((unsigned char)text[0])) key_type = NID_md5; if (!key_type) diff --git a/libntp/timetoa.c b/libntp/timetoa.c index c04d34ea0..f294e1610 100644 --- a/libntp/timetoa.c +++ b/libntp/timetoa.c @@ -57,14 +57,12 @@ format_time_fraction( u_int u; long fraclimit; int notneg; /* flag for non-negative value */ - const char * fmt; ldiv_t qr; DEBUG_REQUIRE(prec != 0); LIB_GETBUF(cp); secs_u = (u_time)secs; - fmt = "-%" UTIME_FORMAT ".%0*ld"; /* check if we need signed or unsigned mode */ notneg = (prec < 0); @@ -92,9 +90,7 @@ format_time_fraction( /* Get the absolute value of the split representation time. */ notneg = notneg || ((time_t)secs_u >= 0); - if (notneg) { - fmt++; /* skip '-' */ - } else { + if (!notneg) { secs_u = ~secs_u; if (0 == frac) secs_u++; @@ -103,7 +99,8 @@ format_time_fraction( } /* finally format the data and return the result */ - snprintf(cp, LIB_BUFLENGTH, fmt, secs_u, prec_u, frac); + snprintf(cp, LIB_BUFLENGTH, "%s%" UTIME_FORMAT ".%0*ld", + notneg? "" : "-", secs_u, prec_u, frac); return cp; } diff --git a/libparse/clk_meinberg.c b/libparse/clk_meinberg.c index bc0ac0e81..a94c3f7a2 100644 --- a/libparse/clk_meinberg.c +++ b/libparse/clk_meinberg.c @@ -157,7 +157,7 @@ mbg_csum( ) { unsigned long sum = 0; - short i; + unsigned int i; for ( i = 0; i < n; i++ ) sum += *p++; diff --git a/libparse/clk_rawdcf.c b/libparse/clk_rawdcf.c index 98848bee8..d6e4b184c 100644 --- a/libparse/clk_rawdcf.c +++ b/libparse/clk_rawdcf.c @@ -125,12 +125,12 @@ clockformat_t clock_rawdcf = static struct dcfparam { - unsigned char *onebits; - unsigned char *zerobits; + const unsigned char *onebits; + const unsigned char *zerobits; } dcfparameter = { - (unsigned char *)"###############RADMLS1248124P124812P1248121241248112481248P??", /* 'ONE' representation */ - (unsigned char *)"--------------------s-------p------p----------------------p__" /* 'ZERO' representation */ + (const unsigned char *)"###############RADMLS1248124P124812P1248121241248112481248P??", /* 'ONE' representation */ + (const unsigned char *)"--------------------s-------p------p----------------------p__" /* 'ZERO' representation */ }; static struct rawdcfcode @@ -182,7 +182,7 @@ static u_long ext_bf( unsigned char *buf, int idx, - unsigned char *zero + const unsigned char *zero ) { u_long sum = 0; @@ -202,7 +202,7 @@ static unsigned pcheck( unsigned char *buf, int idx, - unsigned char *zero + const unsigned char *zero ) { int i,last; @@ -225,8 +225,8 @@ convert_rawdcf( ) { unsigned char *s = buffer; - unsigned char *b = dcfprm->onebits; - unsigned char *c = dcfprm->zerobits; + const unsigned char *b = dcfprm->onebits; + const unsigned char *c = dcfprm->zerobits; int i; parseprintf(DD_RAWDCF,("parse: convert_rawdcf: \"%s\"\n", buffer)); @@ -342,8 +342,8 @@ cvt_rawdcf( last_tcode_t *t = (last_tcode_t *)local; unsigned char *s = (unsigned char *)buffer; unsigned char *e = s + size; - unsigned char *b = dcfparameter.onebits; - unsigned char *c = dcfparameter.zerobits; + const unsigned char *b = dcfparameter.onebits; + const unsigned char *c = dcfparameter.zerobits; u_long rtc = CVT_NONE; unsigned int i, lowmax, highmax, cutoff, span; #define BITS 9 diff --git a/libparse/data_mbg.c b/libparse/data_mbg.c index 97bef35c4..23ca75509 100644 --- a/libparse/data_mbg.c +++ b/libparse/data_mbg.c @@ -266,8 +266,8 @@ mbg_tm_str( tmp->year, tmp->month, tmp->mday, tmp->hour, tmp->minute, tmp->second, tmp->frac, (tmp->offs_from_utc < 0) ? '-' : '+', - abs(tmp->offs_from_utc) / 3600, - (abs(tmp->offs_from_utc) / 60) % 60); + abs((int)tmp->offs_from_utc) / 3600, + (abs((int)tmp->offs_from_utc) / 60) % 60); *buffpp += strlen(*buffpp); mbg_time_status_str(buffpp, tmp->status, size - (*buffpp - s)); @@ -383,7 +383,7 @@ get_mbg_comparam( COM_PARM *comparamp ) { - int i; + size_t i; comparamp->baud_rate = get_lsb_long(buffpp); for (i = 0; i < sizeof(comparamp->framing); i++) diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index f5f326ca4..6c9368fa7 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -58,13 +58,10 @@ static u_short ctlclkstatus (struct refclockstat *); static void ctl_flushpkt (u_char); static void ctl_putdata (const char *, unsigned int, int); static void ctl_putstr (const char *, const char *, size_t); -static void ctl_putdblf (const char *, const char *, double); -const char ctl_def_dbl_fmt[] = "%.3f"; -#define ctl_putdbl(tag, d) ctl_putdblf(tag, ctl_def_dbl_fmt, d) -const char ctl_def_dbl6_fmt[] = "%.6f"; -#define ctl_putdbl6(tag, d) ctl_putdblf(tag, ctl_def_dbl6_fmt, d) -const char ctl_def_sfp_fmt[] = "%g"; -#define ctl_putsfp(tag, sfp) ctl_putdblf(tag, ctl_def_sfp_fmt, \ +static void ctl_putdblf (const char *, int, int, double); +#define ctl_putdbl(tag, d) ctl_putdblf(tag, 1, 3, d) +#define ctl_putdbl6(tag, d) ctl_putdblf(tag, 1, 6, d) +#define ctl_putsfp(tag, sfp) ctl_putdblf(tag, 0, -1, \ FPTOD(sfp)) static void ctl_putuint (const char *, u_long); static void ctl_puthex (const char *, u_long); @@ -811,7 +808,7 @@ static char *reqend; void init_control(void) { - int i; + size_t i; #ifdef HAVE_UNAME uname(&utsnamebuf); @@ -846,9 +843,9 @@ ctl_error( * Fill in the fields. We assume rpkt.sequence and rpkt.associd * have already been filled in. */ - rpkt.r_m_e_op = CTL_RESPONSE | CTL_ERROR | + rpkt.r_m_e_op = (u_char)CTL_RESPONSE | CTL_ERROR | (res_opcode & CTL_OP_MASK); - rpkt.status = htons((errcode << 8) & 0xff00); + rpkt.status = htons((u_short)(errcode << 8) & 0xff00); rpkt.count = 0; /* @@ -923,6 +920,7 @@ save_config( * allow timestamping of the saved config filename with * strftime() format such as: * ntpq -c "saveconfig ntp-%Y%m%d-%H%M%S.conf" + * XXX: Nice feature, but not too safe. */ if (0 == strftime(filename, sizeof(filename), filespec, localtime(&now))) @@ -1007,7 +1005,7 @@ process_control( const struct ctl_proc *cc; keyid_t *pkid; int properlen; - int maclen; + size_t maclen; DPRINTF(3, ("in process_control()\n")); @@ -1023,11 +1021,11 @@ process_control( * If the length is less than required for the header, or * it is a response or a fragment, ignore this. */ - if (rbufp->recv_length < CTL_HEADER_LEN + if (rbufp->recv_length < (int)CTL_HEADER_LEN || (CTL_RESPONSE | CTL_MORE | CTL_ERROR) & pkt->r_m_e_op || pkt->offset != 0) { DPRINTF(1, ("invalid format in control packet\n")); - if (rbufp->recv_length < CTL_HEADER_LEN) + if (rbufp->recv_length < (int)CTL_HEADER_LEN) numctltooshort++; if (CTL_RESPONSE & pkt->r_m_e_op) numctlinputresp++; @@ -1096,7 +1094,7 @@ process_control( res_authenticate = TRUE; pkid = (void *)((char *)pkt + properlen); res_keyid = ntohl(*pkid); - DPRINTF(3, ("recv_len %d, properlen %d, wants auth with keyid %08x, MAC length=%d\n", + DPRINTF(3, ("recv_len %d, properlen %d, wants auth with keyid %08x, MAC length=%zu\n", rbufp->recv_length, properlen, res_keyid, maclen)); @@ -1220,7 +1218,7 @@ ctl_flushpkt( u_char more ) { - int i; + size_t i; int dlen; int sendlen; int maclen; @@ -1347,7 +1345,7 @@ ctl_putdata( /* * Not enough room in this one, flush it out. */ - currentlen = MIN(dlen, dataend - datapt); + currentlen = MIN(dlen, (unsigned int)(dataend - datapt)); memcpy(datapt, dp, currentlen); @@ -1439,7 +1437,8 @@ ctl_putunqstr( static void ctl_putdblf( const char * tag, - const char * fmt, + int use_f, + int precision, double d ) { @@ -1452,8 +1451,9 @@ ctl_putdblf( while (*cq != '\0') *cp++ = *cq++; *cp++ = '='; - NTP_INSIST((cp - buffer) < sizeof(buffer)); - snprintf(cp, sizeof(buffer) - (cp - buffer), fmt, d); + NTP_INSIST((size_t)(cp - buffer) < sizeof(buffer)); + snprintf(cp, sizeof(buffer) - (cp - buffer), use_f ? "%.*f" : "%.*g", + precision, d); cp += strlen(cp); ctl_putdata(buffer, (unsigned)(cp - buffer), 0); } @@ -1477,7 +1477,7 @@ ctl_putuint( *cp++ = *cq++; *cp++ = '='; - NTP_INSIST((cp - buffer) < sizeof(buffer)); + NTP_INSIST((cp - buffer) < (int)sizeof(buffer)); snprintf(cp, sizeof(buffer) - (cp - buffer), "%lu", uval); cp += strlen(cp); ctl_putdata(buffer, (unsigned)( cp - buffer ), 0); @@ -1508,7 +1508,7 @@ ctl_putfs( tm = gmtime(&fstamp); if (NULL == tm) return; - NTP_INSIST((cp - buffer) < sizeof(buffer)); + NTP_INSIST((cp - buffer) < (int)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); @@ -1537,7 +1537,7 @@ ctl_puthex( *cp++ = *cq++; *cp++ = '='; - NTP_INSIST((cp - buffer) < sizeof(buffer)); + NTP_INSIST((cp - buffer) < (int)sizeof(buffer)); snprintf(cp, sizeof(buffer) - (cp - buffer), "0x%lx", uval); cp += strlen(cp); ctl_putdata(buffer,(unsigned)( cp - buffer ), 0); @@ -1563,7 +1563,7 @@ ctl_putint( *cp++ = *cq++; *cp++ = '='; - NTP_INSIST((cp - buffer) < sizeof(buffer)); + NTP_INSIST((cp - buffer) < (int)sizeof(buffer)); snprintf(cp, sizeof(buffer) - (cp - buffer), "%ld", ival); cp += strlen(cp); ctl_putdata(buffer, (unsigned)( cp - buffer ), 0); @@ -1589,7 +1589,7 @@ ctl_putts( *cp++ = *cq++; *cp++ = '='; - NTP_INSIST((cp - buffer) < sizeof(buffer)); + NTP_INSIST((size_t)(cp - buffer) < sizeof(buffer)); snprintf(cp, sizeof(buffer) - (cp - buffer), "0x%08x.%08x", (u_int)ts->l_ui, (u_int)ts->l_uf); cp += strlen(cp); @@ -1621,7 +1621,7 @@ ctl_putadr( cq = numtoa(addr32); else cq = stoa(addr); - NTP_INSIST((cp - buffer) < sizeof(buffer)); + NTP_INSIST((cp - buffer) < (int)sizeof(buffer)); snprintf(cp, sizeof(buffer) - (cp - buffer), "%s", cq); cp += strlen(cp); ctl_putdata(buffer, (unsigned)(cp - buffer), 0); @@ -1658,7 +1658,7 @@ ctl_putrefid( iplim = iptr + sizeof(refid); for ( ; optr < oplim && iptr < iplim && '\0' != *iptr; iptr++, optr++) - if (isprint(*iptr)) + if (isprint((int)*iptr)) *optr = *iptr; else *optr = '.'; @@ -1692,7 +1692,7 @@ ctl_putarray( if (i == 0) i = NTP_SHIFT; i--; - NTP_INSIST((cp - buffer) < sizeof(buffer)); + NTP_INSIST((cp - buffer) < (int)sizeof(buffer)); snprintf(cp, sizeof(buffer) - (cp - buffer), " %.2f", arr[i] * 1e3); cp += strlen(cp); @@ -1715,9 +1715,6 @@ ctl_putsys( double kb; double dtemp; const char *ss; - size_t len; - int firstvarname; - const struct ctl_var *k; #ifdef AUTOKEY struct cert_info *cp; #endif /* AUTOKEY */ @@ -1863,11 +1860,11 @@ ctl_putsys( { char buf[CTL_MAX_DATA_LEN]; //buffPointer, firstElementPointer, buffEndPointer - register char *buffp, *buffend; - register int firstVarName; - register const char *ss; - register int len; - register struct ctl_var *k; + char *buffp, *buffend; + int firstVarName; + const char *ss1; + int len; + const struct ctl_var *k; buffp = buf; buffend = buf + sizeof(buf); @@ -1896,11 +1893,11 @@ ctl_putsys( continue; if (NULL == k->text) continue; - ss = strchr(k->text, '='); - if (NULL == ss) + ss1 = strchr(k->text, '='); + if (NULL == ss1) len = strlen(k->text); else - len = ss - k->text; + len = ss1 - k->text; if (buffp + len + 1 >= buffend) break; if (firstVarName) { @@ -2113,7 +2110,7 @@ ctl_putsys( case CS_K_OFFSET: CTL_IF_KERNLOOP( ctl_putdblf, - (sys_var[varid].text, "%g", to_ms * ntx.offset) + (sys_var[varid].text, 0, -1, to_ms * ntx.offset) ); break; @@ -2127,7 +2124,7 @@ ctl_putsys( case CS_K_MAXERR: CTL_IF_KERNLOOP( ctl_putdblf, - (sys_var[varid].text, "%.6g", + (sys_var[varid].text, 0, 6, to_ms * ntx.maxerror) ); break; @@ -2135,7 +2132,7 @@ ctl_putsys( case CS_K_ESTERR: CTL_IF_KERNLOOP( ctl_putdblf, - (sys_var[varid].text, "%.6g", + (sys_var[varid].text, 0, 6, to_ms * ntx.esterror) ); break; @@ -2159,7 +2156,7 @@ ctl_putsys( case CS_K_PRECISION: CTL_IF_KERNLOOP( ctl_putdblf, - (sys_var[varid].text, "%.6g", + (sys_var[varid].text, 0, 6, to_ms * ntx.precision) ); break; @@ -2902,7 +2899,7 @@ ctl_getitem( cp++; while (cp < reqend && *cp != ',') { *tp++ = *cp++; - if (tp - buf >= sizeof(buf)) { + if ((size_t)(tp - buf) >= sizeof(buf)) { ctl_error(CERR_BADFMT); numctlbadpkts++; NLOG(NLOG_SYSEVENT) @@ -2974,7 +2971,7 @@ read_status( { struct peer *peer; const u_char *cp; - int n; + size_t n; /* a_st holds association ID, status pairs alternating */ u_short a_st[CTL_MAX_DATA_LEN / sizeof(u_short)]; @@ -3032,7 +3029,7 @@ read_peervars(void) const struct ctl_var *v; struct peer *peer; const u_char *cp; - int i; + size_t i; char * valuep; u_char wants[CP_MAXCODE + 1]; u_int gotvar; @@ -3708,7 +3705,7 @@ static void read_mru_list( const char * pch; char * pnonce; int nonce_valid; - int i; + size_t i; int priors; u_short hash; mon_entry * mon; @@ -3737,9 +3734,9 @@ static void read_mru_list( set_var(&in_parms, maxlstint_text, sizeof(maxlstint_text), 0); set_var(&in_parms, laddr_text, sizeof(laddr_text), 0); for (i = 0; i < COUNTOF(last); i++) { - snprintf(buf, sizeof(buf), last_fmt, i); + snprintf(buf, sizeof(buf), last_fmt, (int)i); set_var(&in_parms, buf, strlen(buf) + 1, 0); - snprintf(buf, sizeof(buf), addr_fmt, i); + snprintf(buf, sizeof(buf), addr_fmt, (int)i); set_var(&in_parms, buf, strlen(buf) + 1, 0); } @@ -3758,6 +3755,7 @@ static void read_mru_list( while (NULL != (v = ctl_getitem(in_parms, &val)) && !(EOV & v->flags)) { + int si; if (!strcmp(nonce_text, v->text)) { if (NULL != pnonce) @@ -3780,20 +3778,20 @@ static void read_mru_list( } else if (!strcmp(laddr_text, v->text)) { if (decodenetnum(val, &laddr)) lcladr = getinterface(&laddr, 0); - } else if (1 == sscanf(v->text, last_fmt, &i) && - i < COUNTOF(last)) { + } else if (1 == sscanf(v->text, last_fmt, &si) && + (size_t)si < COUNTOF(last)) { if (2 == sscanf(val, "0x%08x.%08x", &ui, &uf)) { - last[i].l_ui = ui; - last[i].l_uf = uf; - if (!SOCK_UNSPEC(&addr[i]) && - i == priors) + last[si].l_ui = ui; + last[si].l_uf = uf; + if (!SOCK_UNSPEC(&addr[si]) && + si == priors) priors++; } - } else if (1 == sscanf(v->text, addr_fmt, &i) && - i < COUNTOF(addr)) { - if (decodenetnum(val, &addr[i]) - && last[i].l_ui && last[i].l_uf && - i == priors) + } else if (1 == sscanf(v->text, addr_fmt, &si) && + (size_t)si < COUNTOF(addr)) { + if (decodenetnum(val, &addr[si]) + && last[si].l_ui && last[si].l_uf && + si == priors) priors++; } } @@ -3827,7 +3825,7 @@ static void read_mru_list( * Find the starting point if one was provided. */ mon = NULL; - for (i = 0; i < priors; i++) { + for (i = 0; i < (size_t)priors; i++) { hash = MON_HASH(&addr[i]); for (mon = mon_hash[hash]; mon != NULL; @@ -4902,7 +4900,7 @@ set_var( t++; } if (*s == *t && ((*t == '=') || !*t)) { - td = erealloc(k->text, size); + td = erealloc((void *)(intptr_t)k->text, size); memcpy(td, data, size); k->text = td; k->flags = def; @@ -4965,7 +4963,7 @@ free_varlist( struct ctl_var *k; if (kv) { for (k = kv; !(k->flags & EOV); k++) - free((void *)k->text); + free((void *)(intptr_t)k->text); free((void *)kv); } } diff --git a/ntpd/ntp_crypto.c b/ntpd/ntp_crypto.c index 0dc5e3269..4f27ab8bd 100644 --- a/ntpd/ntp_crypto.c +++ b/ntpd/ntp_crypto.c @@ -423,7 +423,6 @@ crypto_recv( int has_mac; /* length of MAC field */ int authlen; /* offset of MAC field */ associd_t associd; /* association ID */ - tstamp_t tstamp = 0; /* timestamp */ tstamp_t fstamp = 0; /* filestamp */ u_int len; /* extension field length */ u_int code; /* extension field opcode */ @@ -448,7 +447,7 @@ crypto_recv( */ authlen = LEN_PKT_NOMAC; hismode = (int)PKT_MODE((&rbufp->recv_pkt)->li_vn_mode); - while ((has_mac = rbufp->recv_length - authlen) > MAX_MAC_LEN) { + while ((has_mac = rbufp->recv_length - authlen) > (int)MAX_MAC_LEN) { pkt = (u_int32 *)&rbufp->recv_pkt + authlen / 4; ep = (struct exten *)pkt; code = ntohl(ep->opcode) & 0xffff0000; @@ -474,7 +473,6 @@ crypto_recv( } if (len >= VALUE_LEN) { - tstamp = ntohl(ep->tstamp); fstamp = ntohl(ep->fstamp); vallen = ntohl(ep->vallen); } @@ -1755,7 +1753,7 @@ crypto_send( ) { u_int len, vallen, siglen, opcode; - int i, j; + u_int i, j; /* * Calculate extension field length and check for buffer @@ -1783,7 +1781,7 @@ crypto_send( i = 0; if (vallen > 0 && vp->ptr != NULL) { j = vallen / 4; - if (j * 4 < (int)vallen) + if (j * 4 < vallen) ep->pkt[i + j++] = 0; memcpy(&ep->pkt[i], vp->ptr, vallen); i += j; @@ -1796,7 +1794,7 @@ crypto_send( ep->pkt[i++] = vp->siglen; if (siglen > 0 && vp->sig != NULL) { j = siglen / 4; - if (j * 4 < (int)siglen) + if (j * 4 < siglen) ep->pkt[i + j++] = 0; memcpy(&ep->pkt[i], vp->sig, siglen); i += j; @@ -1956,7 +1954,7 @@ asn_to_calendar ( struct calendar *pjd /* pointer to result */ ) { - int len; /* length of ASN1_TIME string */ + size_t len; /* length of ASN1_TIME string */ char v[24]; /* writable copy of ASN1_TIME string */ unsigned long temp; /* result from strtoul */ @@ -3058,7 +3056,7 @@ cert_sign( X509_gmtime_adj(X509_get_notAfter(cert), YEAR); subj = X509_get_issuer_name(cert); X509_NAME_add_entry_by_txt(subj, "commonName", MBSTRING_ASC, - hostval.ptr, strlen(hostval.ptr), -1, 0); + hostval.ptr, strlen((const char *)hostval.ptr), -1, 0); subj = X509_get_subject_name(req); X509_set_subject_name(cert, subj); X509_set_pubkey(cert, pkey); @@ -3099,7 +3097,7 @@ cert_sign( vp->vallen = htonl(len); vp->ptr = emalloc(len); ptr = vp->ptr; - i2d_X509(cert, &ptr); + i2d_X509(cert, (unsigned char **)(intptr_t)&ptr); vp->siglen = 0; if (tstamp != 0) { vp->sig = emalloc(sign_siglen); @@ -3431,7 +3429,7 @@ cert_parse( /* * Check for a certificate loop. */ - if (strcmp(hostval.ptr, ret->issuer) == 0) { + if (strcmp((const char *)hostval.ptr, ret->issuer) == 0) { msyslog(LOG_NOTICE, "cert_parse: certificate trail loop %s", ret->subject); diff --git a/ntpd/ntp_filegen.c b/ntpd/ntp_filegen.c index a1703a9d1..4ee90955c 100644 --- a/ntpd/ntp_filegen.c +++ b/ntpd/ntp_filegen.c @@ -617,7 +617,7 @@ filegen_statsdir(void) #ifdef DEBUG void filegen_unregister( - char *name + const char *name ) { struct filegen_entry ** ppfe; diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index d771cf5d8..f01088d4d 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -217,7 +217,7 @@ static isc_boolean_t socket_multicast_disable(endpt *, sockaddr_u *); #ifdef DEBUG static void interface_dump (const endpt *); static void sockaddr_dump (const sockaddr_u *); -static void print_interface (const endpt *, char *, char *); +static void print_interface (const endpt *, const char *, const char *); #define DPRINT_INTERFACE(level, args) do { if (debug >= (level)) { print_interface args; } } while (0) #else #define DPRINT_INTERFACE(level, args) do {} while (0) @@ -550,7 +550,7 @@ sockaddr_dump(const sockaddr_u *psau) * print_interface - helper to output debug information */ static void -print_interface(const endpt *iface, char *pfx, char *sfx) +print_interface(const endpt *iface, const char *pfx, const char *sfx) { printf("%sinterface #%d: fd=%d, bfd=%d, name=%s, flags=0x%x, ifindex=%u, sin=%s", pfx, @@ -1647,16 +1647,15 @@ set_wildcard_reuse( static isc_boolean_t -is_anycast( +check_flags6( sockaddr_u *psau, - const char *name + const char *name, + u_int32 flags6 ) { -#if defined(INCLUDE_IPV6_SUPPORT) && defined(SIOCGIFAFLAG_IN6) && \ - defined(IN6_IFF_ANYCAST) +#if defined(INCLUDE_IPV6_SUPPORT) && defined(SIOCGIFAFLAG_IN6) struct in6_ifreq ifr6; int fd; - u_int32 flags6; if (psau->sa.sa_family != AF_INET6) return ISC_FALSE; @@ -1670,13 +1669,45 @@ is_anycast( return ISC_FALSE; } close(fd); - flags6 = ifr6.ifr_ifru.ifru_flags6; - if ((flags6 & IN6_IFF_ANYCAST) != 0) + if ((ifr6.ifr_ifru.ifru_flags6 & flags6) != 0) return ISC_TRUE; -#endif /* INCLUDE_IPV6_SUPPORT && SIOCGIFAFLAG_IN6 && IN6_IFF_ANYCAST */ +#endif /* INCLUDE_IPV6_SUPPORT && SIOCGIFAFLAG_IN6 */ return ISC_FALSE; } +static isc_boolean_t +is_anycast( + sockaddr_u *psau, + const char *name + ) +{ +#ifdef IN6_IFF_ANYCAST + return check_flags6(psau, name, IN6_IFF_ANYCAST); +#else + return ISC_FALSE; +#endif +} + +static isc_boolean_t +is_valid( + sockaddr_u *psau, + const char *name + ) +{ + u_int32 flags6; + + flags6 = 0; +#ifdef IN6_IFF_DEPARTED + flags6 |= IN6_IFF_DEPARTED; +#endif +#ifdef IN6_IFF_DETACHED + flags6 |= IN6_IFF_DETACHED; +#endif +#ifdef IN6_IFF_TENTATIVE + flags6 |= IN6_IFF_TENTATIVE; +#endif + return check_flags6(psau, name, flags6) ? ISC_FALSE : ISC_TRUE; +} /* * update_interface strategy @@ -1809,6 +1840,12 @@ update_interfaces( if (is_anycast(&enumep.sin, isc_if.name)) continue; + /* + * skip any address that is an invalid state to be used + */ + if (!is_valid(&enumep.sin, isc_if.name)) + continue; + /* * map to local *address* in order to map all duplicate * interfaces to an endpt structure with the appropriate @@ -1969,6 +2006,9 @@ update_interfaces( if (broadcast_client_enabled) io_setbclient(); + if (sys_bclient) + io_setbclient(); + return new_interface_found; } @@ -2314,7 +2354,7 @@ enable_multicast_if( #ifdef IP_MULTICAST_LOOP TYPEOF_IP_MULTICAST_LOOP off = 0; #endif -#ifdef IPV6_MULTICAST_LOOP +#if defined(INCLUDE_IPV6_MULTICAST_SUPPORT) && defined(IPV6_MULTICAST_LOOP) u_int off6 = 0; #endif @@ -2795,7 +2835,6 @@ open_socket( { SOCKET fd; int errval; - char scopetext[16]; /* * int is OK for REUSEADR per * http://www.kohala.com/start/mcast.api.txt @@ -2945,16 +2984,10 @@ open_socket( || debug > 1 #endif ) { - if (SCOPE(addr)) - snprintf(scopetext, sizeof(scopetext), - "%%%d", SCOPE(addr)); - else - scopetext[0] = 0; - msyslog(LOG_ERR, - "bind(%d) AF_INET%s %s%s#%d%s flags 0x%x failed: %m", + "bind(%d) AF_INET%s %s#%d%s flags 0x%x failed: %m", fd, IS_IPV6(addr) ? "6" : "", - stoa(addr), scopetext, SRCPORT(addr), + stoa(addr), SRCPORT(addr), IS_MCAST(addr) ? " (multicast)" : "", interf->flags); } @@ -3198,8 +3231,8 @@ read_refclock_packet( } i = (rp->datalen == 0 - || rp->datalen > sizeof(rb->recv_space)) - ? sizeof(rb->recv_space) + || rp->datalen > (int)sizeof(rb->recv_space)) + ? (int)sizeof(rb->recv_space) : rp->datalen; do { buflen = read(fd, (char *)&rb->recv_space, (u_int)i); @@ -3321,8 +3354,8 @@ fetch_timestamp( tvp->tv_usec = (long)(ticks * 1e6 * sys_tick); } - DPRINTF(4, ("fetch_timestamp: system usec network time stamp: %ld.%06ld\n", - tvp->tv_sec, tvp->tv_usec)); + DPRINTF(4, ("fetch_timestamp: system usec network time stamp: %jd.%06ld\n", + (intmax_t)tvp->tv_sec, (long)tvp->tv_usec)); nts = tval_stamp_to_lfp(*tvp); break; #endif /* HAVE_TIMESTAMP */ @@ -3453,15 +3486,15 @@ read_network_packet( if (AF_INET6 == itf->family) { DPRINTF(1, ("Got an IPv6 packet, from <%s> (%d) to <%s> (%d)\n", stoa(&rb->recv_srcadr), - IN6_IS_ADDR_LOOPBACK(&rb->recv_srcadr.sa6.sin6_addr), + IN6_IS_ADDR_LOOPBACK(PSOCK_ADDR6(&rb->recv_srcadr)), stoa(&itf->sin), - !IN6_IS_ADDR_LOOPBACK(&itf->sin.sa6.sin6_addr) + !IN6_IS_ADDR_LOOPBACK(PSOCK_ADDR6(&itf->sin)) )); } if ( AF_INET6 == itf->family - && IN6_IS_ADDR_LOOPBACK(&rb->recv_srcadr.sa6.sin6_addr) - && !IN6_IS_ADDR_LOOPBACK(&itf->sin.sa6.sin6_addr) + && IN6_IS_ADDR_LOOPBACK(PSOCK_ADDR6(&rb->recv_srcadr)) + && !IN6_IS_ADDR_LOOPBACK(PSOCK_ADDR6(&itf->sin)) ) { packets_dropped++; DPRINTF(1, ("DROPPING that packet\n")); @@ -4038,7 +4071,7 @@ calc_addr_distance( found_greater = FALSE; a1_greater = FALSE; /* suppress pot. uninit. warning */ - for (i = 0; i < sizeof(NSRCADR6(a1)); i++) { + for (i = 0; i < (int)sizeof(NSRCADR6(a1)); i++) { if (!found_greater && NSRCADR6(a1)[i] != NSRCADR6(a2)[i]) { found_greater = TRUE; @@ -4081,7 +4114,7 @@ cmp_addr_distance( return 1; } - for (i = 0; i < sizeof(NSRCADR6(d1)); i++) { + for (i = 0; i < (int)sizeof(NSRCADR6(d1)); i++) { if (NSRCADR6(d1)[i] < NSRCADR6(d2)[i]) return -1; else if (NSRCADR6(d1)[i] > NSRCADR6(d2)[i]) diff --git a/ntpd/ntp_leapsec.c b/ntpd/ntp_leapsec.c index 14b8cd99f..5ac27e7d9 100644 --- a/ntpd/ntp_leapsec.c +++ b/ntpd/ntp_leapsec.c @@ -972,7 +972,7 @@ leapsec_validate( do_hash_data(&mdctx, line+2); else if (!strncmp(line, "#$", 2)) do_hash_data(&mdctx, line+2); - else if (isdigit(line[0])) + else if (isdigit((unsigned char)line[0])) do_hash_data(&mdctx, line); } isc_sha1_final(&mdctx, ldig.hv); diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index 091fcf527..37c3f0325 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -493,11 +493,11 @@ receive( struct exten *ep; #endif /*AUTOKEY */ - if (has_mac % 4 != 0 || has_mac < MIN_MAC_LEN) { + if (has_mac % 4 != 0 || has_mac < (int)MIN_MAC_LEN) { sys_badlength++; return; /* bad length */ } - if (has_mac <= MAX_MAC_LEN) { + if (has_mac <= (int)MAX_MAC_LEN) { skeyid = ntohl(((u_int32 *)pkt)[authlen / 4]); break; @@ -706,7 +706,7 @@ receive( * # if unsync, 0 * % can't happen */ - if (has_mac < MAX_MD5_LEN) { + if (has_mac < (int)MAX_MD5_LEN) { sys_badauth++; return; } @@ -744,7 +744,7 @@ receive( * purposes is zero. Note the hash is saved for * use later in the autokey mambo. */ - if (authlen > LEN_PKT_NOMAC && pkeyid != 0) { + if (authlen > (int)LEN_PKT_NOMAC && pkeyid != 0) { session_key(&rbufp->recv_srcadr, dstadr_sin, skeyid, 0, 2); tkeyid = session_key( @@ -2101,7 +2101,7 @@ poll_update( void peer_clear( struct peer *peer, /* peer structure */ - char *ident /* tally lights */ + const char *ident /* tally lights */ ) { u_char u; @@ -2391,7 +2391,7 @@ clock_select(void) struct peer *peer; int i, j, k, n; int nlist, nl2; - int allow, osurv; + int allow; int speer; double d, e, f, g; double high, low; @@ -2420,7 +2420,6 @@ clock_select(void) * enough to handle all associations. */ osys_peer = sys_peer; - osurv = sys_survivors; sys_survivors = 0; #ifdef LOCKCLOCK sys_leap = LEAP_NOTINSYNC; @@ -2990,7 +2989,7 @@ peer_xmit( ) { struct pkt xpkt; /* transmit packet */ - int sendlen, authlen; + size_t sendlen, authlen; keyid_t xkeyid = 0; /* transmit key ID */ l_fp xmt_tx, xmt_ty; @@ -3074,7 +3073,7 @@ peer_xmit( LFPTOD(&xmt_ty, peer->xleave); #ifdef DEBUG if (debug) - printf("transmit: at %ld %s->%s mode %d len %d\n", + printf("transmit: at %ld %s->%s mode %d len %zu\n", current_time, peer->dstadr ? stoa(&peer->dstadr->sin) : "-", stoa(&peer->srcadr), peer->hmode, sendlen); @@ -3321,7 +3320,7 @@ peer_xmit( * Calculate the next session key. Since extension * fields are present, the cookie value is zero. */ - if (sendlen > LEN_PKT_NOMAC) { + if (sendlen > (int)LEN_PKT_NOMAC) { session_key(&peer->dstadr->sin, &peer->srcadr, xkeyid, 0, 2); } @@ -3363,7 +3362,7 @@ peer_xmit( authtrust(xkeyid, 0); #endif /* AUTOKEY */ if (sendlen > sizeof(xpkt)) { - msyslog(LOG_ERR, "proto: buffer overflow %u", sendlen); + msyslog(LOG_ERR, "proto: buffer overflow %zu", sendlen); exit (-1); } peer->t21_bytes = sendlen; @@ -3388,7 +3387,7 @@ peer_xmit( #ifdef AUTOKEY #ifdef DEBUG if (debug) - printf("transmit: at %ld %s->%s mode %d keyid %08x len %d index %d\n", + printf("transmit: at %ld %s->%s mode %d keyid %08x len %zu index %d\n", current_time, latoa(peer->dstadr), ntoa(&peer->srcadr), peer->hmode, xkeyid, sendlen, peer->keynumber); @@ -3599,7 +3598,7 @@ pool_xmit( &hints, 0, /* no retry */ &pool_name_resolved, - (void *)(u_int)pool->associd); + (void *)(intptr_t)pool->associd); if (!rc) DPRINTF(1, ("pool DNS lookup %s started\n", pool->hostname)); @@ -3705,7 +3704,7 @@ pool_name_resolved( return; } - assoc = (associd_t)(u_int)context; + assoc = (associd_t)(intptr_t)context; pool = findpeerbyassoc(assoc); if (NULL == pool) { msyslog(LOG_ERR, diff --git a/ntpd/ntp_request.c b/ntpd/ntp_request.c index 157304b6d..8ffebad32 100644 --- a/ntpd/ntp_request.c +++ b/ntpd/ntp_request.c @@ -58,7 +58,7 @@ struct req_proc { * Universal request codes */ static const struct req_proc univ_codes[] = { - { NO_REQUEST, NOAUTH, 0, 0 } + { NO_REQUEST, NOAUTH, 0, 0, NULL } }; static void req_ack (sockaddr_u *, endpt *, struct req_pkt *, int); @@ -231,7 +231,7 @@ static endpt *frominter; void init_request (void) { - int i; + size_t i; numrequests = 0; numresppkts = 0; @@ -261,7 +261,7 @@ req_ack( rpkt.auth_seq = AUTH_SEQ(0, 0); rpkt.implementation = inpkt->implementation; rpkt.request = inpkt->request; - rpkt.err_nitems = ERR_NITEMS(errcode, 0); + rpkt.err_nitems = ERR_NITEMS(errcode, 0); rpkt.mbz_itemsize = MBZ_ITEMSIZE(0); /* @@ -448,7 +448,7 @@ process_private( || (++ec, INFO_SEQ(inpkt->auth_seq) != 0) || (++ec, INFO_ERR(inpkt->err_nitems) != 0) || (++ec, INFO_MBZ(inpkt->mbz_itemsize) != 0) - || (++ec, rbufp->recv_length < REQ_LEN_HDR) + || (++ec, rbufp->recv_length < (int)REQ_LEN_HDR) ) { NLOG(NLOG_SYSEVENT) if (current_time >= quiet_until) { @@ -599,11 +599,10 @@ process_private( return; } if (recv_len > REQ_LEN_NOMAC + MAX_MAC_LEN) { - DPRINTF(5, ("bad pkt length %lu\n", - (u_long)recv_len)); + DPRINTF(5, ("bad pkt length %zu\n", recv_len)); msyslog(LOG_ERR, - "process_private: bad pkt length %lu", - (u_long)recv_len); + "process_private: bad pkt length %zu", + recv_len); req_ack(srcadr, inter, inpkt, INFO_ERR_FMT); return; } @@ -2076,7 +2075,7 @@ req_get_traps( { struct info_trap *it; struct ctl_trap *tr; - int i; + size_t i; if (num_ctl_traps == 0) { req_ack(srcadr, inter, inpkt, INFO_ERR_NODATA); diff --git a/ntpd/ntp_restrict.c b/ntpd/ntp_restrict.c index 6e7566713..9948d54d9 100644 --- a/ntpd/ntp_restrict.c +++ b/ntpd/ntp_restrict.c @@ -46,7 +46,7 @@ #define MASK_IPV6_ADDR(dst, src, msk) \ do { \ int idx; \ - for (idx = 0; idx < COUNTOF((dst)->s6_addr); idx++) { \ + for (idx = 0; idx < (int)COUNTOF((dst)->s6_addr); idx++) { \ (dst)->s6_addr[idx] = (src)->s6_addr[idx] \ & (msk)->s6_addr[idx]; \ } \ @@ -298,7 +298,7 @@ match_restrict6_addr( MASK_IPV6_ADDR(&masked, addr, &res->u.v6.mask); if (ADDR6_EQ(&masked, &res->u.v6.addr) && (!(RESM_NTPONLY & res->mflags) - || NTP_PORT == port)) + || NTP_PORT == (int)port)) break; } return res; diff --git a/ntpd/ntp_scanner.c b/ntpd/ntp_scanner.c index 3e098562d..a7c19922b 100644 --- a/ntpd/ntp_scanner.c +++ b/ntpd/ntp_scanner.c @@ -70,12 +70,12 @@ keyword( int token ) { - int i; + size_t i; const char *text; i = token - LOWEST_KEYWORD_ID; - if (i >= 0 && i < COUNTOF(keyword_text)) + if (i < COUNTOF(keyword_text)) text = keyword_text[i]; else text = NULL; @@ -297,7 +297,7 @@ is_integer( /* Check that all the remaining characters are digits */ for (; lexeme[i] != '\0'; i++) { - if (!isdigit(lexeme[i])) + if (!isdigit((unsigned char)lexeme[i])) return FALSE; } @@ -322,7 +322,7 @@ is_u_int( int is_hex; i = 0; - if ('0' == lexeme[i] && 'x' == tolower(lexeme[i + 1])) { + if ('0' == lexeme[i] && 'x' == tolower((unsigned char)lexeme[i + 1])) { i += 2; is_hex = TRUE; } else { @@ -331,9 +331,9 @@ is_u_int( /* Check that all the remaining characters are digits */ for (; lexeme[i] != '\0'; i++) { - if (is_hex && !isxdigit(lexeme[i])) + if (is_hex && !isxdigit((unsigned char)lexeme[i])) return FALSE; - if (!is_hex && !isdigit(lexeme[i])) + if (!is_hex && !isdigit((unsigned char)lexeme[i])) return FALSE; } @@ -357,14 +357,14 @@ is_double( i++; /* Read the integer part */ - for (; lexeme[i] && isdigit(lexeme[i]); i++) + for (; lexeme[i] && isdigit((unsigned char)lexeme[i]); i++) num_digits++; /* Check for the optional decimal point */ if ('.' == lexeme[i]) { i++; /* Check for any digits after the decimal point */ - for (; lexeme[i] && isdigit(lexeme[i]); i++) + for (; lexeme[i] && isdigit((unsigned char)lexeme[i]); i++) num_digits++; } @@ -380,7 +380,7 @@ is_double( return 1; /* There is still more input, read the exponent */ - if ('e' == tolower(lexeme[i])) + if ('e' == tolower((unsigned char)lexeme[i])) i++; else return 0; @@ -390,7 +390,7 @@ is_double( i++; /* Now read the exponent part */ - while (lexeme[i] && isdigit(lexeme[i])) + while (lexeme[i] && isdigit((unsigned char)lexeme[i])) i++; /* Check if we are done */ @@ -455,7 +455,7 @@ create_string_token( * ignore end of line whitespace */ pch = lexeme; - while (*pch && isspace(*pch)) + while (*pch && isspace((unsigned char)*pch)) pch++; if (!*pch) { @@ -481,7 +481,7 @@ yylex( ) { static follby followedby = FOLLBY_TOKEN; - int i; + size_t i; int instring; int yylval_was_set; int converted; @@ -502,7 +502,7 @@ yylex( if (EOF == ch) { - if (!input_from_file || !curr_include_level) + if (!input_from_file || curr_include_level <= 0) return 0; FCLOSE(fp[curr_include_level]); @@ -640,7 +640,7 @@ yylex( } else if (is_u_int(yytext)) { yylval_was_set = TRUE; if ('0' == yytext[0] && - 'x' == tolower(yytext[1])) + 'x' == tolower((unsigned char)yytext[1])) converted = sscanf(&yytext[2], "%x", &yylval.U_int); else diff --git a/ntpd/ntp_util.c b/ntpd/ntp_util.c index a7da52b86..c4bc9011a 100644 --- a/ntpd/ntp_util.c +++ b/ntpd/ntp_util.c @@ -679,7 +679,7 @@ record_raw_stats( int version, int mode, int stratum, - int poll, + int ppoll, int precision, double root_delay, /* seconds */ double root_dispersion,/* seconds */ @@ -702,7 +702,7 @@ record_raw_stats( stoa(srcadr), dstadr ? stoa(dstadr) : "-", ulfptoa(t1, 9), ulfptoa(t2, 9), ulfptoa(t3, 9), ulfptoa(t4, 9), - leap, version, mode, stratum, poll, precision, + leap, version, mode, stratum, ppoll, precision, root_delay, root_dispersion, refid_str(refid, stratum)); fflush(rawstats.fp); } diff --git a/ntpd/ntpd.c b/ntpd/ntpd.c index ef1baa703..c017ef34d 100644 --- a/ntpd/ntpd.c +++ b/ntpd/ntpd.c @@ -168,8 +168,8 @@ int root_dropped; char *user; /* User to switch to */ char *group; /* group to switch to */ const char *chrootdir; /* directory to chroot to */ -int sw_uid; -int sw_gid; +uid_t sw_uid; +gid_t sw_gid; char *endp; struct group *gr; struct passwd *pw; @@ -937,6 +937,10 @@ getgroup: msyslog(LOG_ERR, "Cannot setegid() to group `%s': %m", group); exit (-1); } + if (group) + setgroups(1, &sw_gid); + else + initgroups(pw->pw_name, pw->pw_gid); if (user && setuid(sw_uid)) { msyslog(LOG_ERR, "Cannot setuid() to user `%s': %m", user); exit (-1); diff --git a/ntpd/refclock_acts.c b/ntpd/refclock_acts.c index 36322fd91..f62cc466b 100644 --- a/ntpd/refclock_acts.c +++ b/ntpd/refclock_acts.c @@ -343,7 +343,7 @@ acts_receive( up->bufptr = up->buf; acts_message(peer, up->buf); } - } else if (!iscntrl(*tptr)) { + } else if (!iscntrl((unsigned char)*tptr)) { *up->bufptr++ = *tptr; if (*tptr == '*' || *tptr == '#') { up->tstamp = pp->lastrec; @@ -515,7 +515,7 @@ acts_timeout( up->unit); fd = refclock_open(device, SPEED232, LDISC_ACTS | LDISC_RAW | LDISC_REMOTE); - if (fd <= 0) { + if (fd < 0) { msyslog(LOG_ERR, "acts: open fails %m"); return; } diff --git a/ntpd/refclock_arc.c b/ntpd/refclock_arc.c index b2c063e43..e5d4cb440 100644 --- a/ntpd/refclock_arc.c +++ b/ntpd/refclock_arc.c @@ -843,7 +843,7 @@ send_slow( static int get2(char *p, int *val) { - if (!isdigit((int)p[0]) || !isdigit((int)p[1])) return 0; + if (!isdigit((unsigned char)p[0]) || !isdigit((unsigned char)p[1])) return 0; *val = (p[0] - '0') * 10 + p[1] - '0'; return 1; } @@ -851,7 +851,7 @@ get2(char *p, int *val) static int get1(char *p, int *val) { - if (!isdigit((int)p[0])) return 0; + if (!isdigit((unsigned char)p[0])) return 0; *val = p[0] - '0'; return 1; } @@ -943,7 +943,7 @@ arc_receive( #ifdef DEBUG if(debug) { /* Show \r as `R', other non-printing char as `?'. */ printf("arc: stamp -->%c<-- (%d chars rcvd)\n", - ((c == '\r') ? 'R' : (isgraph((int)c) ? c : '?')), + ((c == '\r') ? 'R' : (isgraph((unsigned char)c) ? c : '?')), rbufp->recv_length); } #endif diff --git a/ntpd/refclock_chu.c b/ntpd/refclock_chu.c index 9c7093d2c..6b1ae5554 100644 --- a/ntpd/refclock_chu.c +++ b/ntpd/refclock_chu.c @@ -967,15 +967,11 @@ chu_serial_receive( struct recvbuf *rbufp /* receive buffer structure pointer */ ) { - struct chuunit *up; - struct refclockproc *pp; struct peer *peer; u_char *dpt; /* receive buffer pointer */ peer = rbufp->recv_peer; - pp = peer->procptr; - up = pp->unitptr; dpt = (u_char *)&rbufp->recv_space; chu_decode(peer, *dpt, rbufp->recv_time); diff --git a/ntpd/refclock_gpsdjson.c b/ntpd/refclock_gpsdjson.c index 2ca6389a6..2171a4fff 100644 --- a/ntpd/refclock_gpsdjson.c +++ b/ntpd/refclock_gpsdjson.c @@ -204,8 +204,8 @@ static int syslogok(clockprocT * const pp, gpsd_unitT * const up); * data and selecting the GPS device name we created from our unit * number. [Note: This is a format string!] */ -static const char * s_logon = - "?WATCH={\"enable\":true,\"json\":true,\"device\":\"%s\"};\r\n"; +#define s_logon \ + "?WATCH={\"enable\":true,\"json\":true,\"device\":\"%s\"};\r\n" /* We keep a static list of network addresses for 'localhost:gpsd', and * we try to connect to them in round-robin fashion. @@ -854,7 +854,7 @@ process_tpv( const char * gps_time; int gps_mode; double ept, epp, epx, epy, epv; - int log2; + int xlog2; gps_mode = (int)json_object_lookup_int_default( jctx, 0, "mode", 0); @@ -920,9 +920,9 @@ process_tpv( ept = min(ept, epp ); ept = min(ept, 0.5 ); ept = max(ept, 1.0-9); - ept = frexp(ept, &log2); + ept = frexp(ept, &xlog2); - peer->precision = log2; + peer->precision = xlog2; } /* ------------------------------------------------------------------ */ @@ -1270,7 +1270,7 @@ convert_ascii_time( ep = strptime(gps_time, "%Y-%m-%dT%H:%M:%S", &gd); if (*ep == '.') { dw = 100000000; - while (isdigit(*++ep)) { + while (isdigit((unsigned char)*++ep)) { ts.tv_nsec += (*ep - '0') * dw; dw /= 10; } diff --git a/ntpd/refclock_heath.c b/ntpd/refclock_heath.c index 435d8f6c4..aed056c91 100644 --- a/ntpd/refclock_heath.c +++ b/ntpd/refclock_heath.c @@ -379,7 +379,7 @@ heath_receive( /* * Determine synchronization and last update */ - if (!isdigit((int)dsec)) + if (!isdigit((unsigned char)dsec)) pp->leap = LEAP_NOTINSYNC; else { pp->nsec = (dsec - '0') * 100000000; diff --git a/ntpd/refclock_irig.c b/ntpd/refclock_irig.c index 46c01fbb7..abc94f62e 100644 --- a/ntpd/refclock_irig.c +++ b/ntpd/refclock_irig.c @@ -762,7 +762,7 @@ irig_baud( * persist for lots of samples. */ up->exing = -up->yxing; - if (fabs(up->envxing - up->envphase) <= 1) { + if (abs(up->envxing - up->envphase) <= 1) { up->tcount++; if (up->tcount > 20 * up->tc) { up->tc++; @@ -980,10 +980,8 @@ irig_poll( ) { struct refclockproc *pp; - struct irigunit *up; pp = peer->procptr; - up = pp->unitptr; if (pp->coderecv == pp->codeproc) { refclock_report(peer, CEVNT_TIMEOUT); diff --git a/ntpd/refclock_jjy.c b/ntpd/refclock_jjy.c index d8ec6b744..e279ee307 100644 --- a/ntpd/refclock_jjy.c +++ b/ntpd/refclock_jjy.c @@ -297,9 +297,9 @@ struct refclock refclock_jjy = { static struct { - char commandNumber ; - char *commandLog ; - char *command ; + const char commandNumber ; + const char *commandLog ; + const char *command ; int commandLength ; } tristate_jjy01_command_sequence[] = { @@ -337,8 +337,8 @@ static struct static struct { char commandNumber ; - char *commandLog ; - char *command ; + const char *commandLog ; + const char *command ; int commandLength ; } tristate_gpsclock01_command_sequence[] = { @@ -741,7 +741,7 @@ static int jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp ) { #ifdef DEBUG - static char *sFunctionName = "jjy_receive_tristate_jjy01" ; + static const char *sFunctionName = "jjy_receive_tristate_jjy01" ; #endif struct jjyunit *up ; @@ -756,7 +756,7 @@ jjy_receive_tristate_jjy01 ( struct recvbuf *rbufp ) char sLogText [ MAX_LOGTEXT ], sReplyText [ MAX_LOGTEXT ] ; - char *pCmd ; + const char *pCmd ; int iCmdLen ; /* @@ -930,7 +930,7 @@ static int jjy_receive_cdex_jst2000 ( struct recvbuf *rbufp ) { #ifdef DEBUG - static char *sFunctionName = "jjy_receive_cdex_jst2000" ; + static const char *sFunctionName = "jjy_receive_cdex_jst2000" ; #endif struct jjyunit *up ; @@ -1010,7 +1010,7 @@ static int jjy_receive_echokeisokuki_lt2000 ( struct recvbuf *rbufp ) { #ifdef DEBUG - static char *sFunctionName = "jjy_receive_echokeisokuki_lt2000" ; + static const char *sFunctionName = "jjy_receive_echokeisokuki_lt2000" ; #endif struct jjyunit *up ; @@ -1052,7 +1052,7 @@ jjy_receive_echokeisokuki_lt2000 ( struct recvbuf *rbufp ) if ( up->operationmode == 1 ) { #ifdef DEBUG if ( debug ) { - printf ( "%s (refclock_jjy.c) : send '#'\n", sFunctionName ) ; + printf ( "%s (refclock_jjy.c) : send '#'\n", __func__ ) ; } #endif if ( write ( pp->io.fd, "#",1 ) != 1 ) { @@ -1169,7 +1169,7 @@ static int jjy_receive_citizentic_jjy200 ( struct recvbuf *rbufp ) { #ifdef DEBUG - static char *sFunctionName = "jjy_receive_citizentic_jjy200" ; + static const char *sFunctionName = "jjy_receive_citizentic_jjy200" ; #endif struct jjyunit *up ; @@ -1264,7 +1264,7 @@ static int jjy_receive_tristate_gpsclock01 ( struct recvbuf *rbufp ) { #ifdef DEBUG - static char *sFunctionName = "jjy_receive_tristate_gpsclock01" ; + static const char *sFunctionName = "jjy_receive_tristate_gpsclock01" ; #endif struct jjyunit *up ; @@ -1279,7 +1279,7 @@ jjy_receive_tristate_gpsclock01 ( struct recvbuf *rbufp ) char sLogText [ MAX_LOGTEXT ], sReplyText [ MAX_LOGTEXT ] ; - char *pCmd ; + const char *pCmd ; int iCmdLen ; /* @@ -1519,13 +1519,13 @@ static void jjy_poll_tristate_jjy01 ( int unit, struct peer *peer ) { #ifdef DEBUG - static char *sFunctionName = "jjy_poll_tristate_jjy01" ; + static const char *sFunctionName = "jjy_poll_tristate_jjy01" ; #endif struct jjyunit *up; struct refclockproc *pp; - char *pCmd ; + const char *pCmd ; int iCmdLen ; pp = peer->procptr; @@ -1641,13 +1641,13 @@ static void jjy_poll_tristate_gpsclock01 ( int unit, struct peer *peer ) { #ifdef DEBUG - static char *sFunctionName = "jjy_poll_tristate_gpsclock01" ; + static const char *sFunctionName = "jjy_poll_tristate_gpsclock01" ; #endif struct jjyunit *up; struct refclockproc *pp; - char *pCmd ; + const char *pCmd ; int iCmdLen ; pp = peer->procptr; @@ -1690,7 +1690,7 @@ jjy_poll_tristate_gpsclock01 ( int unit, struct peer *peer ) static void printableString ( char *sOutput, int iOutputLen, char *sInput, int iInputLen ) { - char *printableControlChar[] = { + const char *printableControlChar[] = { "", "", "", "", "", "", "", "", "" , "" , "" , "" , @@ -1700,16 +1700,15 @@ printableString ( char *sOutput, int iOutputLen, char *sInput, int iInputLen ) "", "" , "", "", "" , "" , "" , "" , " " } ; + + size_t i, j, n ; size_t InputLen; size_t OutputLen; - size_t i; - size_t j; - size_t n; InputLen = (size_t)iInputLen; OutputLen = (size_t)iOutputLen; for ( i = j = 0 ; i < InputLen && j < OutputLen ; i ++ ) { - if ( isprint( sInput[i] ) ) { + if ( isprint( (unsigned char)sInput[i] ) ) { n = 1 ; if ( j + 1 >= OutputLen ) break ; @@ -1732,7 +1731,7 @@ printableString ( char *sOutput, int iOutputLen, char *sInput, int iInputLen ) j += n ; } - sOutput[min(j, iOutputLen - 1)] = '\0' ; + sOutput[min(j, (size_t)iOutputLen - 1)] = '\0' ; } diff --git a/ntpd/refclock_jupiter.c b/ntpd/refclock_jupiter.c index 377fc5632..02b33dfb3 100644 --- a/ntpd/refclock_jupiter.c +++ b/ntpd/refclock_jupiter.c @@ -136,8 +136,8 @@ static int jupiter_config (struct instance *); static void jupiter_debug (struct peer *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4))); -static char * jupiter_parse_t (struct instance *, u_short *); -static char * jupiter_parse_gpos (struct instance *, u_short *); +static const char * jupiter_parse_t (struct instance *, u_short *); +static const char * jupiter_parse_gpos (struct instance *, u_short *); static void jupiter_platform (struct instance *, u_int); static void jupiter_poll (int, struct peer *); static void jupiter_control (int, const struct refclockstat *, @@ -275,7 +275,7 @@ jupiter_shutdown(int unit, struct peer *peer) static int jupiter_config(struct instance *instance) { - jupiter_debug(instance->peer, "jupiter_config", "init receiver"); + jupiter_debug(instance->peer, __func__, "init receiver"); /* * Initialize the unit variables @@ -283,8 +283,7 @@ jupiter_config(struct instance *instance) instance->sloppyclockflag = instance->peer->procptr->sloppyclockflag; instance->moving = !!(instance->sloppyclockflag & CLK_FLAG2); if (instance->moving) - jupiter_debug(instance->peer, "jupiter_config", - "mobile platform"); + jupiter_debug(instance->peer, __func__, "mobile platform"); instance->pollcnt = 2; instance->polled = 0; @@ -368,7 +367,7 @@ jupiter_ppsapi( #if DEBUG if (debug) { time_pps_getparams(instance->pps_handle, &instance->pps_params); - jupiter_debug(instance->peer, "refclock_jupiter", + jupiter_debug(instance->peer, __func__, "pps capability 0x%x version %d mode 0x%x kern %d", capability, instance->pps_params.api_version, instance->pps_params.mode, instance->hardpps); @@ -498,8 +497,7 @@ jupiter_control( instance->sloppyclockflag = pp->sloppyclockflag; if ((instance->sloppyclockflag & CLK_FLAG2) != (sloppyclockflag & CLK_FLAG2)) { - jupiter_debug(peer, - "jupiter_control", + jupiter_debug(peer, __func__, "mode switch: reset receiver"); jupiter_config(instance); return; @@ -513,10 +511,11 @@ jupiter_control( static void jupiter_receive(struct recvbuf *rbufp) { - int bpcnt, cc, size, ppsret; + size_t bpcnt; + int cc, size, ppsret; time_t last_timecode; u_int32 laststime; - char *cp; + const char *cp; u_char *bp; u_short *sp; struct jid *ip; @@ -535,7 +534,7 @@ jupiter_receive(struct recvbuf *rbufp) bpcnt = rbufp->recv_length; /* This shouldn't happen */ - if (bpcnt > (int)sizeof(instance->sbuf) - instance->ssize) + if (bpcnt > sizeof(instance->sbuf) - instance->ssize) bpcnt = sizeof(instance->sbuf) - instance->ssize; /* Append to input buffer */ @@ -543,7 +542,7 @@ jupiter_receive(struct recvbuf *rbufp) instance->ssize += bpcnt; /* While there's at least a header and we parse an intact message */ - while (instance->ssize > sizeof(*hp) && (cc = jupiter_recv(instance)) > 0) { + while (instance->ssize > (int)sizeof(*hp) && (cc = jupiter_recv(instance)) > 0) { instance->pollcnt = 2; tstamp = rbufp->recv_time; @@ -554,8 +553,8 @@ jupiter_receive(struct recvbuf *rbufp) case JUPITER_O_PULSE: if (size != sizeof(struct jpulse)) { - jupiter_debug(peer, - "jupiter_receive", "pulse: len %d != %u", + jupiter_debug(peer, __func__, + "pulse: len %d != %u", size, (int)sizeof(struct jpulse)); refclock_report(peer, CEVNT_BADREPLY); break; @@ -574,7 +573,7 @@ jupiter_receive(struct recvbuf *rbufp) laststime = instance->stime; instance->stime = DS2UI(((struct jpulse *)sp)->stime); if (laststime != 0 && instance->stime - laststime <= 21) { - jupiter_debug(peer, "jupiter_receive", + jupiter_debug(peer, __func__, "avoided firmware bug (stime %.2f, laststime %.2f)", (double)instance->stime * 0.01, (double)laststime * 0.01); break; @@ -595,8 +594,8 @@ jupiter_receive(struct recvbuf *rbufp) /* Parse timecode (even when there's no pps) */ last_timecode = instance->timecode; if ((cp = jupiter_parse_t(instance, sp)) != NULL) { - jupiter_debug(peer, - "jupiter_receive", "pulse: %s", cp); + jupiter_debug(peer, __func__, + "pulse: %s", cp); break; } @@ -645,24 +644,24 @@ jupiter_receive(struct recvbuf *rbufp) case JUPITER_O_GPOS: if (size != sizeof(struct jgpos)) { - jupiter_debug(peer, - "jupiter_receive", "gpos: len %d != %u", + jupiter_debug(peer, __func__, + "gpos: len %d != %u", size, (int)sizeof(struct jgpos)); refclock_report(peer, CEVNT_BADREPLY); break; } if ((cp = jupiter_parse_gpos(instance, sp)) != NULL) { - jupiter_debug(peer, - "jupiter_receive", "gpos: %s", cp); + jupiter_debug(peer, __func__, + "gpos: %s", cp); break; } break; case JUPITER_O_ID: if (size != sizeof(struct jid)) { - jupiter_debug(peer, - "jupiter_receive", "id: len %d != %u", + jupiter_debug(peer, __func__, + "id: len %d != %u", size, (int)sizeof(struct jid)); refclock_report(peer, CEVNT_BADREPLY); break; @@ -672,8 +671,8 @@ jupiter_receive(struct recvbuf *rbufp) * just powered instance, it needs to be reconfigured. */ ip = (struct jid *)sp; - jupiter_debug(peer, - "jupiter_receive", "%s chan ver %s, %s (%s)", + jupiter_debug(peer, __func__, + "%s chan ver %s, %s (%s)", ip->chans, ip->vers, ip->date, ip->opts); msyslog(LOG_DEBUG, "jupiter_receive: %s chan ver %s, %s (%s)", @@ -681,8 +680,7 @@ jupiter_receive(struct recvbuf *rbufp) if (instance->wantid) instance->wantid = 0; else { - jupiter_debug(peer, - "jupiter_receive", "reset receiver"); + jupiter_debug(peer, __func__, "reset receiver"); jupiter_config(instance); /* * Restore since jupiter_config() just @@ -693,8 +691,7 @@ jupiter_receive(struct recvbuf *rbufp) break; default: - jupiter_debug(peer, - "jupiter_receive", "unknown message id %d", + jupiter_debug(peer, __func__, "unknown message id %d", getshort(hp->id)); break; } @@ -707,7 +704,7 @@ jupiter_receive(struct recvbuf *rbufp) } } -static char * +static const char * jupiter_parse_t(struct instance *instance, u_short *sp) { struct tm *tm; @@ -757,8 +754,8 @@ jupiter_parse_t(struct instance *instance, u_short *sp) } else if (sweek == 0 && instance->lastsweek == WEEKSECS - 1) { ++instance->gweek; - jupiter_debug(instance->peer, - "jupiter_parse_t", "NEW gps week %u", instance->gweek); + jupiter_debug(instance->peer, __func__, + "NEW gps week %u", instance->gweek); } /* @@ -774,14 +771,14 @@ jupiter_parse_t(struct instance *instance, u_short *sp) * Then we warped. */ if (instance->lastsweek == sweek) - jupiter_debug(instance->peer, - "jupiter_parse_t", "gps sweek not incrementing (%d)", + jupiter_debug(instance->peer, __func__, + "gps sweek not incrementing (%d)", sweek); else if (instance->lastsweek != 2 * WEEKSECS && instance->lastsweek + 1 != sweek && !(sweek == 0 && instance->lastsweek == WEEKSECS - 1)) - jupiter_debug(instance->peer, - "jupiter_parse_t", "gps sweek jumped (was %d, now %d)", + jupiter_debug(instance->peer, __func__, + "gps sweek jumped (was %d, now %d)", instance->lastsweek, sweek); instance->lastsweek = sweek; @@ -792,16 +789,16 @@ jupiter_parse_t(struct instance *instance, u_short *sp) if (last_timecode == 0) /* XXX debugging */ - jupiter_debug(instance->peer, - "jupiter_parse_t", "UTC (gweek/sweek %u/%u)", + jupiter_debug(instance->peer, __func__, + "UTC (gweek/sweek %u/%u)", instance->gweek, sweek); else { /* XXX debugging */ tm = gmtime(&last_timecode); cp = asctime(tm); - jupiter_debug(instance->peer, - "jupiter_parse_t", "UTC %.24s (gweek/sweek %u/%u)", + jupiter_debug(instance->peer, __func__, + "UTC %.24s (gweek/sweek %u/%u)", cp, instance->gweek, sweek); /* Billboard last_timecode (which is now the current time) */ @@ -829,7 +826,7 @@ jupiter_parse_t(struct instance *instance, u_short *sp) return (NULL); } -static char * +static const char * jupiter_parse_gpos(struct instance *instance, u_short *sp) { struct jgpos *jg; @@ -861,8 +858,8 @@ jupiter_parse_gpos(struct instance *instance, u_short *sp) tm = gmtime(&t); cp = asctime(tm); - jupiter_debug(instance->peer, - "jupiter_parse_g", "GPS %.24s (gweek/sweek %u/%u)", + jupiter_debug(instance->peer, __func__, + "GPS %.24s (gweek/sweek %u/%u)", cp, instance->gpos_gweek, instance->gpos_sweek); return (NULL); } @@ -903,7 +900,7 @@ static char * jupiter_send(struct instance *instance, struct jheader *hp) { u_int len, size; - int cc; + ssize_t cc; u_short *sp; static char errstr[132]; @@ -921,7 +918,7 @@ jupiter_send(struct instance *instance, struct jheader *hp) msnprintf(errstr, sizeof(errstr), "write: %m"); return (errstr); } else if (cc != (int)size) { - snprintf(errstr, sizeof(errstr), "short write (%d != %u)", cc, size); + snprintf(errstr, sizeof(errstr), "short write (%zd != %u)", cc, size); return (errstr); } return (NULL); @@ -954,7 +951,7 @@ jupiter_reqmsg(struct instance *instance, u_int id, rp->trigger = putshort(interval == 0); rp->interval = putshort(interval); if ((cp = jupiter_send(instance, hp)) != NULL) - jupiter_debug(instance->peer, "jupiter_reqmsg", "%u: %s", id, cp); + jupiter_debug(instance->peer, __func__, "%u: %s", id, cp); } /* Cancel periodic message output */ @@ -973,7 +970,7 @@ jupiter_canmsg(struct instance *instance, u_int id) hp = &canmsg; hp->id = putshort(id); if ((cp = jupiter_send(instance, hp)) != NULL) - jupiter_debug(instance->peer, "jupiter_canmsg", "%u: %s", id, cp); + jupiter_debug(instance->peer, __func__, "%u: %s", id, cp); } /* Request a single message output */ @@ -992,7 +989,7 @@ jupiter_reqonemsg(struct instance *instance, u_int id) hp = &reqonemsg; hp->id = putshort(id); if ((cp = jupiter_send(instance, hp)) != NULL) - jupiter_debug(instance->peer, "jupiter_reqonemsg", "%u: %s", id, cp); + jupiter_debug(instance->peer, __func__, "%u: %s", id, cp); } /* Set the platform dynamics */ @@ -1017,7 +1014,7 @@ jupiter_platform(struct instance *instance, u_int platform) pp = &platmsg.jplat; pp->platform = putshort(platform); if ((cp = jupiter_send(instance, hp)) != NULL) - jupiter_debug(instance->peer, "jupiter_platform", "%u: %s", platform, cp); + jupiter_debug(instance->peer, __func__, "%u: %s", platform, cp); } /* Checksum "len" shorts */ @@ -1054,13 +1051,14 @@ jupiter_recv(struct instance *instance) hp = (struct jheader *)sp; if (getshort(hp->sync) != JUPITER_SYNC) { /* Wasn't at the front, sync up */ - jupiter_debug(instance->peer, "jupiter_recv", "syncing"); + jupiter_debug(instance->peer, __func__, "syncing"); bp = (u_char *)sp; n = size; while (n >= 2) { if (bp[0] != (JUPITER_SYNC & 0xff)) { /* - jupiter_debug(instance->peer, "{0x%x}", bp[0]); + jupiter_debug(instance->peer, __func__, + "{0x%x}", bp[0]); */ ++bp; --n; @@ -1069,13 +1067,14 @@ jupiter_recv(struct instance *instance) if (bp[1] == ((JUPITER_SYNC >> 8) & 0xff)) break; /* - jupiter_debug(instance->peer, "{0x%x 0x%x}", bp[0], bp[1]); + jupiter_debug(instance->peer, __func__, + "{0x%x 0x%x}", bp[0], bp[1]); */ bp += 2; n -= 2; } /* - jupiter_debug(instance->peer, "\n"); + jupiter_debug(instance->peer, __func__, "\n"); */ /* Shuffle data to front of input buffer */ if (n > 0) @@ -1088,7 +1087,7 @@ jupiter_recv(struct instance *instance) if (jupiter_cksum(sp, (cc / sizeof(u_short) - 1)) != getshort(hp->hsum)) { - jupiter_debug(instance->peer, "jupiter_recv", "bad header checksum!"); + jupiter_debug(instance->peer, __func__, "bad header checksum!"); /* This is drastic but checksum errors should be rare */ instance->ssize = 0; return (0); @@ -1106,7 +1105,7 @@ jupiter_recv(struct instance *instance) sp = (u_short *)(hp + 1); if (jupiter_cksum(sp, len) != getshort(sp[len])) { jupiter_debug(instance->peer, - "jupiter_recv", "bad payload checksum!"); + __func__, "bad payload checksum!"); /* This is drastic but checksum errors should be rare */ instance->ssize = 0; return (0); diff --git a/ntpd/refclock_neoclock4x.c b/ntpd/refclock_neoclock4x.c index a0067e9c4..6fda0f078 100644 --- a/ntpd/refclock_neoclock4x.c +++ b/ntpd/refclock_neoclock4x.c @@ -143,7 +143,7 @@ static void neol_jdn_to_ymd (unsigned long, int *, int *, int *); static void neol_localtime (unsigned long, int* , int*, int*, int*, int*, int*); static unsigned long neol_mktime (int, int, int, int, int, int); #if !defined(NEOCLOCK4X_FIRMWARE) -static int neol_query_firmware (int, int, char *, int); +static int neol_query_firmware (int, int, char *, size_t); static int neol_check_firmware (int, const char*, char *); #endif @@ -785,9 +785,9 @@ neol_hexatoi_len(const char str[], int i; int n = 0; - for(i=0; isxdigit((int)str[i]) && i < maxlen; i++) + for(i=0; isxdigit((unsigned char)str[i]) && i < maxlen; i++) { - hexdigit = isdigit((int)str[i]) ? toupper(str[i]) - '0' : toupper(str[i]) - 'A' + 10; + hexdigit = isdigit((unsigned char)str[i]) ? toupper((unsigned char)str[i]) - '0' : toupper((unsigned char)str[i]) - 'A' + 10; n = 16 * n + hexdigit; } *result = n; @@ -803,7 +803,7 @@ neol_atoi_len(const char str[], int i; int n = 0; - for(i=0; isdigit((int)str[i]) && i < maxlen; i++) + for(i=0; isdigit((unsigned char)str[i]) && i < maxlen; i++) { digit = str[i] - '0'; n = 10 * n + digit; @@ -898,10 +898,10 @@ static int neol_query_firmware(int fd, int unit, char *firmware, - int maxlen) + size_t maxlen) { char tmpbuf[256]; - int len; + size_t len; int lastsearch; unsigned char c; int last_c_was_crlf; @@ -1001,7 +1001,7 @@ neol_query_firmware(int fd, tmpbuf[len++] = (char) c; } tmpbuf[len] = '\0'; - if(len > sizeof(tmpbuf)-5) + if (len > sizeof(tmpbuf)-5) break; } } diff --git a/ntpd/refclock_nmea.c b/ntpd/refclock_nmea.c index 58867f47b..aac267047 100644 --- a/ntpd/refclock_nmea.c +++ b/ntpd/refclock_nmea.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "ntpd.h" #include "ntp_io.h" @@ -311,7 +312,7 @@ static int unfold_century (struct calendar * jd, u_int32 rec_ui); static int gpsfix_century (struct calendar * jd, const gps_weektm * wd, u_short * ccentury); static l_fp eval_gps_time (struct peer * peer, const struct calendar * gpst, - const struct timespec * gpso, const l_fp * recv); + const struct timespec * gpso, const l_fp * xrecv); static int nmead_open (const char * device); static void save_ltc (struct refclockproc * const, const char * const, @@ -406,7 +407,7 @@ nmea_start( size_t devlen; u_int32 rate; int baudrate; - char * baudtext; + const char * baudtext; /* Get baudrate choice from mode byte bits 4/5/6 */ @@ -1145,7 +1146,7 @@ nmea_poll( */ if (peer->ttl & NMEA_EXTLOG_MASK) { /* Log & reset counters with extended logging */ - char *nmea = pp->a_lastcode; + const char *nmea = pp->a_lastcode; if (*nmea == '\0') nmea = "(none)"; mprintf_clock_stats( &peer->srcadr, "%s %u %u %u %u %u %u", @@ -1779,7 +1780,7 @@ eval_gps_time( struct peer * peer, /* for logging etc */ const struct calendar * gpst, /* GPS time stamp */ const struct timespec * tofs, /* GPS frac second & offset */ - const l_fp * recv /* receive time stamp */ + const l_fp * xrecv /* receive time stamp */ ) { struct refclockproc * const pp = peer->procptr; @@ -1835,7 +1836,7 @@ eval_gps_time( } /* - get unfold base: day of full recv time - 512 weeks */ - vi64 = ntpcal_ntp_to_ntp(recv->l_ui, NULL); + vi64 = ntpcal_ntp_to_ntp(xrecv->l_ui, NULL); rs64 = ntpcal_daysplit(&vi64); rcv_sec = rs64.lo; rcv_day = rs64.hi - 512 * 7; @@ -1845,7 +1846,7 @@ eval_gps_time( * fractional day of the receive time, we shift the base day for * the unfold by 1. */ if ( gps_sec < rcv_sec - || (gps_sec == rcv_sec && retv.l_uf < recv->l_uf)) + || (gps_sec == rcv_sec && retv.l_uf < xrecv->l_uf)) rcv_day += 1; /* - don't warp ahead of GPS invention! */ diff --git a/ntpd/refclock_oncore.c b/ntpd/refclock_oncore.c index 3bc60bf50..30924b8bb 100644 --- a/ntpd/refclock_oncore.c +++ b/ntpd/refclock_oncore.c @@ -328,7 +328,7 @@ struct instance { u_char printed; u_char polled; u_long ev_serial; - int Rcvptr; + unsigned Rcvptr; u_char Rcvbuf[500]; u_char BEHa[160]; /* Ba, Ea or Ha */ u_char BEHn[80]; /* Bn , En , or Hn */ @@ -436,47 +436,47 @@ static struct msg_desc { int shmem; } oncore_messages[] = { /* Ea and En first since they're most common */ - { "Ea", 76, oncore_msg_BaEaHa, "mdyyhmsffffaaaaoooohhhhmmmmvvhhddtntimsdimsdimsdimsdimsdimsdimsdimsdsC" }, - { "Ba", 68, oncore_msg_BaEaHa, "mdyyhmsffffaaaaoooohhhhmmmmvvhhddtntimsdimsdimsdimsdimsdimsdsC" }, - { "Ha", 154, oncore_msg_BaEaHa, "mdyyhmsffffaaaaoooohhhhmmmmaaaaoooohhhhmmmmVVvvhhddntimsiddimsiddimsiddimsiddimsiddimsiddimsiddimsiddimsiddimsiddimsiddimsiddssrrccooooTTushmvvvvvvC" }, - { "Bn", 59, oncore_msg_BnEnHn, "otaapxxxxxxxxxxpysreensffffsffffsffffsffffsffffsffffC" }, - { "En", 69, oncore_msg_BnEnHn, "otaapxxxxxxxxxxpysreensffffsffffsffffsffffsffffsffffsffffsffffC" }, - { "Hn", 78, oncore_msg_BnEnHn, "" }, - { "Ab", 10, 0, "" }, - { "Ac", 11, 0, "" }, - { "Ad", 11, oncore_msg_Adef, "" }, - { "Ae", 11, oncore_msg_Adef, "" }, - { "Af", 15, oncore_msg_Adef, "" }, - { "Ag", 8, oncore_msg_Ag, "" }, /* Satellite mask angle */ - { "As", 20, oncore_msg_As, "" }, - { "At", 8, oncore_msg_At, "" }, - { "Au", 12, 0, "" }, - { "Av", 8, 0, "" }, - { "Aw", 8, 0, "" }, - { "Ay", 11, oncore_msg_Ay, "" }, - { "Az", 11, oncore_msg_Az, "" }, - { "AB", 8, 0, "" }, - { "Bb", 92, 0, "" }, - { "Bd", 23, oncore_msg_Bd, "" }, - { "Bj", 8, oncore_msg_Bj, "" }, - { "Bl", 41, oncore_msg_Bl, "" }, - { "Ca", 9, oncore_msg_CaFaIa, "" }, - { "Cb", 33, oncore_msg_Cb, "" }, - { "Cf", 7, oncore_msg_Cf, "" }, - { "Cg", 8, 0, "" }, - { "Ch", 9, 0, "" }, - { "Cj", 294, oncore_msg_Cj, "" }, - { "Ek", 71, 0, "" }, - { "Fa", 9, oncore_msg_CaFaIa, "" }, - { "Ga", 20, oncore_msg_Ga, "" }, - { "Gb", 17, oncore_msg_Gb, "" }, - { "Gc", 8, oncore_msg_Gc, "" }, - { "Gd", 8, 0, "" }, - { "Ge", 8, 0, "" }, - { "Gj", 21, oncore_msg_Gj, "" }, - { "Ia", 10, oncore_msg_CaFaIa, "" }, - { "Sz", 8, oncore_msg_Sz, "" }, - { {0}, 7, 0, "" } + { "Ea", 76, oncore_msg_BaEaHa, "mdyyhmsffffaaaaoooohhhhmmmmvvhhddtntimsdimsdimsdimsdimsdimsdimsdimsdsC", 0 }, + { "Ba", 68, oncore_msg_BaEaHa, "mdyyhmsffffaaaaoooohhhhmmmmvvhhddtntimsdimsdimsdimsdimsdimsdsC", 0 }, + { "Ha", 154, oncore_msg_BaEaHa, "mdyyhmsffffaaaaoooohhhhmmmmaaaaoooohhhhmmmmVVvvhhddntimsiddimsiddimsiddimsiddimsiddimsiddimsiddimsiddimsiddimsiddimsiddimsiddssrrccooooTTushmvvvvvvC", 0 }, + { "Bn", 59, oncore_msg_BnEnHn, "otaapxxxxxxxxxxpysreensffffsffffsffffsffffsffffsffffC", 0 }, + { "En", 69, oncore_msg_BnEnHn, "otaapxxxxxxxxxxpysreensffffsffffsffffsffffsffffsffffsffffsffffC", 0 }, + { "Hn", 78, oncore_msg_BnEnHn, "", 0 }, + { "Ab", 10, 0, "", 0 }, + { "Ac", 11, 0, "", 0 }, + { "Ad", 11, oncore_msg_Adef, "", 0 }, + { "Ae", 11, oncore_msg_Adef, "", 0 }, + { "Af", 15, oncore_msg_Adef, "", 0 }, + { "Ag", 8, oncore_msg_Ag, "", 0 }, /* Satellite mask angle */ + { "As", 20, oncore_msg_As, "", 0 }, + { "At", 8, oncore_msg_At, "", 0 }, + { "Au", 12, 0, "", 0 }, + { "Av", 8, 0, "", 0 }, + { "Aw", 8, 0, "", 0 }, + { "Ay", 11, oncore_msg_Ay, "", 0 }, + { "Az", 11, oncore_msg_Az, "", 0 }, + { "AB", 8, 0, "", 0 }, + { "Bb", 92, 0, "", 0 }, + { "Bd", 23, oncore_msg_Bd, "", 0 }, + { "Bj", 8, oncore_msg_Bj, "", 0 }, + { "Bl", 41, oncore_msg_Bl, "", 0 }, + { "Ca", 9, oncore_msg_CaFaIa, "", 0 }, + { "Cb", 33, oncore_msg_Cb, "", 0 }, + { "Cf", 7, oncore_msg_Cf, "", 0 }, + { "Cg", 8, 0, "", 0 }, + { "Ch", 9, 0, "", 0 }, + { "Cj", 294, oncore_msg_Cj, "", 0 }, + { "Ek", 71, 0, "", 0 }, + { "Fa", 9, oncore_msg_CaFaIa, "", 0 }, + { "Ga", 20, oncore_msg_Ga, "", 0 }, + { "Gb", 17, oncore_msg_Gb, "", 0 }, + { "Gc", 8, oncore_msg_Gc, "", 0 }, + { "Gd", 8, 0, "", 0 }, + { "Ge", 8, 0, "", 0 }, + { "Gj", 21, oncore_msg_Gj, "", 0 }, + { "Ia", 10, oncore_msg_CaFaIa, "", 0 }, + { "Sz", 8, oncore_msg_Sz, "", 0 }, + { {0}, 7, 0, "", 0 } }; @@ -848,7 +848,7 @@ oncore_ppsapi( ) { int cap, mode, mode1; - char *cp; + const char *cp; if (time_pps_getcap(instance->pps_h, &cap) < 0) { oncore_log_f(instance, LOG_ERR, "time_pps_getcap failed: %m"); @@ -932,11 +932,11 @@ oncore_init_shmem( struct instance *instance ) { - int i, l, n, fd, shmem_old_size, n1; + int l, fd; u_char *cp, *cp1, *buf, *shmem_old; struct msg_desc *mp; struct stat sbuf; - size_t shmem_length; + size_t i, n, n1, shmem_length, shmem_old_size; /* * The first thing we do is see if there is an instance->shmem_fname file (still) @@ -1210,8 +1210,9 @@ oncore_read_config( */ FILE *fd; - char *cp, *cc, *ca, line[100], units[2], device[64], **cpp; - char *dirs[] = { "/etc/ntp", "/etc", 0 }; + char *cc, *ca, line[100], units[2], device[64]; + const char *dirs[] = { "/etc/ntp", "/etc", 0 }; + const char *cp, **cpp; int i, sign, lat_flg, long_flg, ht_flg, mode, mask; double f1, f2, f3; @@ -1239,19 +1240,20 @@ oncore_read_config( mode = mask = 0; lat_flg = long_flg = ht_flg = 0; while (fgets(line, 100, fd)) { + char *cpw; /* Remove comments */ - if ((cp = strchr(line, '#'))) - *cp = '\0'; + if ((cpw = strchr(line, '#'))) + *cpw = '\0'; /* Remove trailing space */ for (i = strlen(line); - i > 0 && isascii((int)line[i - 1]) && isspace((int)line[i - 1]); + i > 0 && isascii((unsigned char)line[i - 1]) && isspace((unsigned char)line[i - 1]); ) line[--i] = '\0'; /* Remove leading space */ - for (cc = line; *cc && isascii((int)*cc) && isspace((int)*cc); cc++) + for (cc = line; *cc && isascii((unsigned char)*cc) && isspace((unsigned char)*cc); cc++) continue; /* Stop if nothing left */ @@ -1260,16 +1262,16 @@ oncore_read_config( /* Uppercase the command and find the arg */ for (ca = cc; *ca; ca++) { - if (isascii((int)*ca)) { - if (islower((int)*ca)) { - *ca = toupper(*ca); - } else if (isspace((int)*ca) || (*ca == '=')) + if (isascii((unsigned char)*ca)) { + if (islower((unsigned char)*ca)) { + *ca = toupper((unsigned char)*ca); + } else if (isspace((unsigned char)*ca) || (*ca == '=')) break; } } /* Remove space (and possible =) leading the arg */ - for (; *ca && isascii((int)*ca) && (isspace((int)*ca) || (*ca == '=')); ca++) + for (; *ca && isascii((unsigned char)*ca) && (isspace((unsigned char)*ca) || (*ca == '=')); ca++) continue; if (!strncmp(cc, "STATUS", (size_t) 6) || !strncmp(cc, "SHMEM", (size_t) 5)) { @@ -1278,9 +1280,9 @@ oncore_read_config( } /* Uppercase argument as well */ - for (cp = ca; *cp; cp++) - if (isascii((int)*cp) && islower((int)*cp)) - *cp = toupper(*cp); + for (cpw = ca; *cpw; cpw++) + if (isascii((unsigned char)*cpw) && islower((unsigned char)*cpw)) + *cpw = toupper((unsigned char)*cpw); if (!strncmp(cc, "LAT", (size_t) 3)) { f1 = f2 = f3 = 0; @@ -1477,8 +1479,7 @@ oncore_consume( struct instance *instance ) { - int i, m; - unsigned l; + unsigned i, m, l; while (rcvptr >= 7) { if (rcvbuf[0] != '@' || rcvbuf[1] != '@') { @@ -1984,7 +1985,7 @@ oncore_msg_Ag( size_t len ) { - char *cp; + const char *cp; cp = "set to"; if (instance->o_state == ONCORE_RUN) @@ -2503,9 +2504,9 @@ oncore_msg_Bl( size_t len ) { - int chan, id, subframe, valid, page, i, j, tow; + int subframe, valid, page, i, j, tow; int day_now, day_lsf; - char *cp; + const char *cp; enum { WARN_NOT_YET, WARN_0, @@ -2516,8 +2517,6 @@ oncore_msg_Bl( day_now = day_lsf = 0; cp = NULL; /* keep gcc happy */ - chan = buf[4] & 0377; - id = buf[5] & 0377; subframe = buf[6] & 017; valid = (buf[6] >> 4) & 017; page = buf[7]; @@ -2889,19 +2888,20 @@ oncore_msg_Cj_id( size_t len ) { - char *cp, *cp1, *cp2, Model[21]; + char *cp2, Model[21]; + const char *cp, *cp1; /* Write Receiver ID message to clockstats file */ instance->Cj[294] = '\0'; - for (cp=(char *)instance->Cj; cp< (char *) &instance->Cj[294]; ) { - cp1 = strchr(cp, '\r'); - if (!cp1) - cp1 = (char *)&instance->Cj[294]; - *cp1 = '\0'; + for (cp= (char *)instance->Cj; cp< (char *) &instance->Cj[294]; ) { + char *cpw = strchr(cp, '\r'); + if (!cpw) + cpw = (char *)&instance->Cj[294]; + *cpw = '\0'; oncore_log(instance, LOG_NOTICE, cp); - *cp1 = '\r'; - cp = cp1+2; + *cpw = '\r'; + cp = cpw+2; } /* next, the Firmware Version and Revision numbers */ @@ -2916,7 +2916,7 @@ oncore_msg_Cj_id( ; cp1 = cp; cp2 = Model; - for (; !isspace((int)*cp) && cp-cp1 < 20; cp++, cp2++) + for (; !isspace((unsigned char)*cp) && cp-cp1 < 20; cp++, cp2++) *cp2 = *cp; *cp2 = '\0'; @@ -3046,7 +3046,7 @@ oncore_msg_Cj_init( if (mode != 0) { /* cable delay in ns */ memcpy(Cmd, oncore_cmd_Az, (size_t) sizeof(oncore_cmd_Az)); - w32_buf(&Cmd[-2+4], instance->delay); + w32_buf(&Cmd[-2+4], (int)instance->delay); oncore_sendmsg(instance, Cmd, sizeof(oncore_cmd_Az)); /* 6,8,12 */ /* PPS offset in ns */ @@ -3146,7 +3146,7 @@ oncore_msg_Gb( size_t len ) { - char * gmts; + const char * gmts; int mo, d, y, h, m, s, gmth, gmtm; mo = buf[4]; @@ -3177,7 +3177,7 @@ oncore_msg_Gc( size_t len ) { - char *tbl[] = {"OFF", "ON", "SATELLITE", "TRAIM" }; + const char *tbl[] = {"OFF", "ON", "SATELLITE", "TRAIM" }; instance->pps_control_msg_seen = 1; oncore_log_f(instance, LOG_INFO, "PPS Control set to %s", @@ -3202,7 +3202,7 @@ oncore_msg_Gj( }; int dt; - char *cp; + const char *cp; instance->saw_Gj = 1; /* flag, saw_Gj, dont need to try Bj in check_leap */ @@ -3282,7 +3282,7 @@ oncore_antenna_report( struct instance *instance, enum antenna_state new_state) { - char *cp; + const char *cp; if (instance->ant_state == new_state) return; diff --git a/ntpd/refclock_parse.c b/ntpd/refclock_parse.c index 052ec3a5e..f76c05ff1 100644 --- a/ntpd/refclock_parse.c +++ b/ntpd/refclock_parse.c @@ -1537,7 +1537,7 @@ clear_err( { if (lstate == ERR_ALL) { - int i; + size_t i; for (i = 0; i < ERR_CNT; i++) { @@ -1638,7 +1638,7 @@ mkreadable( if (!hex && /* no binary only */ (*src != '\\') && /* no plain \ */ (*src != '"') && /* no " */ - isprint((int)*src)) /* only printables */ + isprint((unsigned char)*src)) /* only printables */ { /* they are easy... */ *buffer++ = *src++; blen--; @@ -1771,6 +1771,16 @@ static bind_t io_bindings[] = }, { (char *)0, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, } }; @@ -2452,6 +2462,31 @@ init_iobinding( ** support routines **/ +static NTP_PRINTF(4, 5) char * +ap(char *buffer, size_t len, char *pos, const char *fmt, ...) +{ + va_list va; + int l; + size_t rem = len - (pos - buffer); + + if (rem == 0) + return pos; + + va_start(va, fmt); + l = vsnprintf(pos, rem, fmt, va); + va_end(va); + + if (l != -1) { + rem--; + if (rem >= (size_t)l) + pos += l; + else + pos += rem; + } + + return pos; +} + /*-------------------------------------------------- * convert a flag field to a string */ @@ -2480,7 +2515,7 @@ parsestate( { PARSEB_TIMECODE, "TIME CODE" }, { PARSEB_PPS, "PPS" }, { PARSEB_POSITION, "POSITION" }, - { 0 } + { 0, NULL } }; static struct sbits @@ -2493,13 +2528,11 @@ parsestate( { PARSEB_S_PPS, "PPS SIGNAL" }, { PARSEB_S_ANTENNA, "ANTENNA" }, { PARSEB_S_POSITION, "POSITION" }, - { 0 } + { 0, NULL } }; int i; char *s, *t; - - *buffer = '\0'; s = t = buffer; i = 0; @@ -2508,42 +2541,37 @@ parsestate( if (flagstrings[i].bit & lstate) { if (s != t) - strlcpy(t, "; ", BUFFER_SIZES(buffer, t, size)); - if (strlcat(t, flagstrings[i].name, BUFFER_SIZES(buffer, t, size)) < - BUFFER_SIZES(buffer, t, size)) - t += strlen(t); + t = ap(buffer, size, t, "; "); + t = ap(buffer, size, t, "%s", flagstrings[i].name); } i++; } if (lstate & (PARSEB_S_LEAP|PARSEB_S_ANTENNA|PARSEB_S_PPS|PARSEB_S_POSITION)) { - if (s != t && - strlcpy(t, "; ", BUFFER_SIZES(buffer, t, size)) < - BUFFER_SIZES(buffer, t, size)) - t += strlen(t); + if (s != t) + t = ap(buffer, size, t, "; "); + + t = ap(buffer, size, t, "("); - if (strlcpy(t, "(", BUFFER_SIZES(buffer, t, size)) < - BUFFER_SIZES(buffer, t, size)) - s = t = t + strlen(t); + s = t; i = 0; while (sflagstrings[i].bit) { if (sflagstrings[i].bit & lstate) { - if (t != s && - strlcpy(t, "; ", BUFFER_SIZES(buffer, t, size)) < - BUFFER_SIZES(buffer, t, size)) - t += 2; + if (t != s) + { + t = ap(buffer, size, t, "; "); + } - if (strlcpy(t, sflagstrings[i].name, BUFFER_SIZES(buffer, t, size)) < - BUFFER_SIZES(buffer, t, size)) - t += strlen(t); + t = ap(buffer, size, t, "%s", + sflagstrings[i].name); } i++; } - strlcpy(t, ")", BUFFER_SIZES(buffer, t, size)); + t = ap(buffer, size, t, ")"); } return buffer; } @@ -2571,10 +2599,12 @@ parsestatus( { CVT_BADDATE, "DATE ILLEGAL" }, { CVT_BADTIME, "TIME ILLEGAL" }, { CVT_ADDITIONAL, "ADDITIONAL DATA" }, - { 0 } + { 0, NULL } }; int i; + char *t; + t = buffer; *buffer = '\0'; i = 0; @@ -2582,9 +2612,9 @@ parsestatus( { if (flagstrings[i].bit & lstate) { - if (buffer[0]) - strlcat(buffer, "; ", size); - strlcat(buffer, flagstrings[i].name, size); + if (t == buffer) + t = ap(buffer, size, t, "; "); + t = ap(buffer, size, t, "%s", flagstrings[i].name); } i++; } @@ -2614,12 +2644,12 @@ clockstatus( { CEVNT_PROP, "PROPAGATION DELAY" }, { CEVNT_BADDATE, "ILLEGAL DATE" }, { CEVNT_BADTIME, "ILLEGAL TIME" }, - { (unsigned)~0L } + { (unsigned)~0L, NULL } }; int i; i = 0; - while (flagstrings[i].value != ~0) + while (flagstrings[i].value != (u_int)~0) { if (flagstrings[i].value == lstate) { @@ -2647,10 +2677,11 @@ l_mktime( char *t; buffer[0] = '\0'; + t = buffer; if ((tmp = delta / (60*60*24)) != 0) { - snprintf(buffer, BUFFER_SIZE(buffer, buffer), "%ldd+", (u_long)tmp); + t = ap(buffer, sizeof(buffer), t, "%ldd+", (u_long)tmp); delta -= tmp * 60*60*24; } @@ -2659,10 +2690,8 @@ l_mktime( m = delta % 60; delta /= 60; - t = buffer + strlen(buffer); - - snprintf(t, BUFFER_SIZE(buffer, t), "%02d:%02d:%02d", - (int)delta, (int)m, (int)s); + t = ap(buffer, sizeof(buffer), t, "%02d:%02d:%02d", + (int)delta, (int)m, (int)s); return buffer; } @@ -2853,7 +2882,7 @@ parse_ppsapi( ) { int cap, mode_ppsoffset; - char *cp; + const char *cp; parse->flags &= ~PARSE_PPSCLOCK; @@ -2961,7 +2990,7 @@ parse_start( type = CLK_TYPE(peer); unit = CLK_UNIT(peer); - if ((type == ~0) || (parse_clockinfo[type].cl_description == (char *)0)) + if ((type == (u_int)~0) || (parse_clockinfo[type].cl_description == (char *)0)) { msyslog(LOG_ERR, "PARSE receiver #%d: parse_start: unsupported clock type %d (max %d)", unit, CLK_REALTYPE(peer), ncltypes-1); @@ -3233,12 +3262,9 @@ parse_start( parse_shutdown(CLK_UNIT(parse->peer), peer); /* let our cleaning staff do the work */ return 0; /* well, ok - special initialisation broke */ } - - tmp_ctl.parseformat.parse_count = strlcpy(tmp_ctl.parseformat.parse_buffer, - parse->parse_type->cl_format, - sizeof(tmp_ctl.parseformat.parse_buffer)); - if (tmp_ctl.parseformat.parse_count >= sizeof(tmp_ctl.parseformat.parse_buffer)) - tmp_ctl.parseformat.parse_count = sizeof(tmp_ctl.parseformat.parse_buffer) - 1; + + strlcpy(tmp_ctl.parseformat.parse_buffer, parse->parse_type->cl_format, sizeof(tmp_ctl.parseformat.parse_buffer)); + tmp_ctl.parseformat.parse_count = strlen(tmp_ctl.parseformat.parse_buffer); if (!PARSE_SETFMT(parse, &tmp_ctl)) { @@ -3408,7 +3434,7 @@ parse_poll( parse->generic->polls++; if (parse->pollneeddata && - ((current_time - parse->pollneeddata) > (1<<(max(min(parse->peer->hpoll, parse->peer->ppoll), parse->peer->minpoll))))) + ((int)(current_time - parse->pollneeddata) > (1<<(max(min(parse->peer->hpoll, parse->peer->ppoll), parse->peer->minpoll))))) { /* * start worrying when exceeding a poll inteval @@ -3521,16 +3547,16 @@ parse_control( } start = tt = add_var(&out->kv_list, 128, RO|DEF); - snprintf(tt, 128, "refclock_time=\""); - tt += strlen(tt); + tt = ap(start, 128, tt, "refclock_time=\""); if (parse->timedata.parse_time.fp.l_ui == 0) { - strlcpy(tt, "\"", BUFFER_SIZES(start, tt, 128)); + tt = ap(start, 128, tt, "\""); } else { - snprintf(tt, 128, "%s\"", gmprettydate(&parse->timedata.parse_time.fp)); + tt = ap(start, 128, tt, "%s\"", + gmprettydate(&parse->timedata.parse_time.fp)); } if (!PARSE_GETTIMECODE(parse, &tmpctl)) @@ -3541,8 +3567,7 @@ parse_control( else { start = tt = add_var(&out->kv_list, 512, RO|DEF); - snprintf(tt, 512, "refclock_status=\""); - tt += strlen(tt); + tt = ap(start, 512, tt, "refclock_status=\""); /* * copy PPS flags from last read transaction (informational only) @@ -3550,9 +3575,11 @@ parse_control( tmpctl.parsegettc.parse_state |= parse->timedata.parse_state & (PARSEB_PPS|PARSEB_S_PPS); - (void) parsestate(tmpctl.parsegettc.parse_state, tt, BUFFER_SIZES(start, tt, 512)); + (void)parsestate(tmpctl.parsegettc.parse_state, tt, BUFFER_SIZES(start, tt, 512)); - strlcat(tt, "\"", BUFFER_SIZES(start, tt, 512)); + tt += strlen(tt); + + tt = ap(start, 512, tt, "\""); if (tmpctl.parsegettc.parse_count) mkascii(outstatus+strlen(outstatus), (int)(sizeof(outstatus)- strlen(outstatus) - 1), @@ -3569,11 +3596,19 @@ parse_control( } else { - tt = add_var(&out->kv_list, 80, RO|DEF); - snprintf(tt, 80, "refclock_format=\""); + int count = tmpctl.parseformat.parse_count - 1; + + start = tt = add_var(&out->kv_list, 80, RO|DEF); + tt = ap(start, 80, tt, "refclock_format=\""); - strlcat(tt, tmpctl.parseformat.parse_buffer, 80); - strlcat(tt,"\"", 80); + if (count > 0) { + tt = ap(start, 80, tt, "%*.*s", + count, + count, + tmpctl.parseformat.parse_buffer); + } + + tt = ap(start, 80, tt, "\""); } /* @@ -3581,8 +3616,7 @@ parse_control( */ start = tt = add_var(&out->kv_list, LEN_STATES, RO|DEF); - strlcpy(tt, "refclock_states=\"", LEN_STATES); - tt += strlen(tt); + tt = ap(start, LEN_STATES, tt, "refclock_states=\""); for (i = 0; i <= CEVNT_MAX; i++) { @@ -3616,14 +3650,15 @@ parse_control( (int)(percent / 100), (int)(percent % 100)); if ((count = strlen(item)) < (LEN_STATES - 40 - (tt - start))) { - strlcpy(tt, item, BUFFER_SIZES(start, tt, LEN_STATES)); - tt += count; + tt = ap(start, LEN_STATES, tt, + "%s", item); } sum += s_time; } } - snprintf(tt, BUFFER_SIZES(start, tt, LEN_STATES), "; running time: %s\"", l_mktime(sum)); + tt = ap(start, LEN_STATES, tt, + "; running time: %s\"", l_mktime(sum)); tt = add_var(&out->kv_list, 32, RO); snprintf(tt, 32, "refclock_id=\"%s\"", parse->parse_type->cl_id); @@ -4297,32 +4332,32 @@ gps16x_message( char *p, *b; status = get_lsb_short(&bufp); - snprintf(buffer, sizeof(buffer), "meinberg_gps_status=\"[0x%04x] ", status); + p = b = buffer; + p = ap(buffer, sizeof(buffer), p, + "meinberg_gps_status=\"[0x%04x] ", + status); if (status) { - p = b = buffer + strlen(buffer); + b = p; while (s->flag) { if (status & s->flag) { if (p != b) { - *p++ = ','; - *p++ = ' '; + p = ap(buffer, sizeof(buffer), p, ", "); } - strlcat(p, (const char *)s->string, sizeof(buffer)); + p = ap(buffer, sizeof(buffer), p, "%s", (const char *)s->string); } s++; } - - *p++ = '"'; - *p = '\0'; + p = ap(buffer, sizeof(buffer), p, "\""); } else { - strlcat(buffer, "\"", sizeof(buffer)); + p = ap(buffer, sizeof(buffer), p, "\""); } set_var(&parse->kv, buffer, strlen(buffer)+1, RO|DEF); @@ -4373,53 +4408,54 @@ gps16x_message( { ANT_INFO antinfo; char buffer[512]; - char *p; + char *p, *q; get_mbg_antinfo(&bufp, &antinfo); - snprintf(buffer, sizeof(buffer), "meinberg_antenna_status=\""); - p = buffer + strlen(buffer); - + p = buffer; + p = ap(buffer, sizeof(buffer), p, "meinberg_antenna_status=\""); switch (antinfo.status) { case ANT_INVALID: - strlcat(p, "", BUFFER_SIZE(buffer, p)); - p += strlen(p); + p = ap(buffer, sizeof(buffer), + p, ""); break; case ANT_DISCONN: - strlcat(p, "DISCONNECTED since ", BUFFER_SIZE(buffer, p)); + q = ap(buffer, sizeof(buffer), + p, "DISCONNECTED since "); NLOG(NLOG_CLOCKSTATUS) ERR(ERR_BADSTATUS) msyslog(LOG_ERR,"PARSE receiver #%d: ANTENNA FAILURE: %s", CLK_UNIT(parse->peer), p); - p += strlen(p); + p = q; mbg_tm_str(&p, &antinfo.tm_disconn, BUFFER_SIZE(buffer, p)); *p = '\0'; break; case ANT_RECONN: - strlcat(p, "RECONNECTED on ", BUFFER_SIZE(buffer, p)); - p += strlen(p); + p = ap(buffer, sizeof(buffer), + p, "RECONNECTED on "); mbg_tm_str(&p, &antinfo.tm_reconn, BUFFER_SIZE(buffer, p)); - snprintf(p, BUFFER_SIZE(buffer, p), ", reconnect clockoffset %c%ld.%07ld s, disconnect time ", + p = ap(buffer, sizeof(buffer), + p, ", reconnect clockoffset %c%ld.%07ld s, disconnect time ", (antinfo.delta_t < 0) ? '-' : '+', ABS(antinfo.delta_t) / 10000, ABS(antinfo.delta_t) % 10000); - p += strlen(p); mbg_tm_str(&p, &antinfo.tm_disconn, BUFFER_SIZE(buffer, p)); *p = '\0'; break; default: - snprintf(p, BUFFER_SIZE(buffer, p), "bad status 0x%04x", antinfo.status); - p += strlen(p); + p = ap(buffer, sizeof(buffer), + p, "bad status 0x%04x", + antinfo.status); break; } - strlcat(p, "\"", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "\""); - set_var(&parse->kv, buffer, strlen(buffer)+1, RO|DEF); + set_var(&parse->kv, buffer, sizeof(buffer), RO|DEF); } break; @@ -4438,102 +4474,101 @@ gps16x_message( int i; p = buffer; - strlcpy(buffer, "gps_tot_51=\"", BUFFER_SIZE(buffer, p)); - p += strlen(p); + p = ap(buffer, sizeof(buffer), + p, "gps_tot_51=\""); mbg_tgps_str(&p, &cfgh.tot_51, BUFFER_SIZE(buffer, p)); - strlcpy(p, "\"", BUFFER_SIZE(buffer, p)); - set_var(&parse->kv, buffer, strlen(buffer)+1, RO); + p = ap(buffer, sizeof(buffer), + p, "\""); + set_var(&parse->kv, buffer, sizeof(buffer), RO); p = buffer; - strlcpy(buffer, "gps_tot_63=\"", BUFFER_SIZE(buffer, p)); - p += strlen(p); + p = ap(buffer, sizeof(buffer), + p, "gps_tot_63=\""); mbg_tgps_str(&p, &cfgh.tot_63, BUFFER_SIZE(buffer, p)); - strlcpy(p, "\"", BUFFER_SIZE(buffer, p)); - set_var(&parse->kv, buffer, strlen(buffer)+1, RO); + p = ap(buffer, sizeof(buffer), + p, "\""); + set_var(&parse->kv, buffer, sizeof(buffer), RO); p = buffer; - strlcpy(buffer, "gps_t0a=\"", BUFFER_SIZE(buffer, p)); - p += strlen(p); + p = ap(buffer, sizeof(buffer), + p, "gps_t0a=\""); mbg_tgps_str(&p, &cfgh.t0a, BUFFER_SIZE(buffer, p)); - strlcpy(p, "\"", BUFFER_SIZE(buffer, p)); - set_var(&parse->kv, buffer, strlen(buffer)+1, RO); + p = ap(buffer, sizeof(buffer), + p, "\""); + set_var(&parse->kv, buffer, sizeof(buffer), RO); for (i = MIN_SVNO; i < MAX_SVNO; i++) { p = buffer; - snprintf(p, BUFFER_SIZE(buffer, p), "gps_cfg[%d]=\"[0x%x] ", i, cfgh.cfg[i]); - p += strlen(p); + p = ap(buffer, sizeof(buffer), p, "gps_cfg[%d]=\"[0x%x] ", i, cfgh.cfg[i]); switch (cfgh.cfg[i] & 0x7) { case 0: - strlcpy(p, "BLOCK I", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "BLOCK I"); break; case 1: - strlcpy(p, "BLOCK II", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "BLOCK II"); break; default: - strlcpy(p, "bad CFG", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "bad CFG"); break; } - strlcat(p, "\"", BUFFER_SIZE(buffer, p)); - set_var(&parse->kv, buffer, strlen(buffer)+1, RO); + p = ap(buffer, sizeof(buffer), p, "\""); + set_var(&parse->kv, buffer, sizeof(buffer), RO); p = buffer; - snprintf(p, BUFFER_SIZE(buffer, p), "gps_health[%d]=\"[0x%x] ", i, cfgh.health[i]); - p += strlen(p); + p = ap(buffer, sizeof(buffer), p, "gps_health[%d]=\"[0x%x] ", i, cfgh.health[i]); switch ((cfgh.health[i] >> 5) & 0x7 ) { case 0: - strlcpy(p, "OK;", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "OK;"); break; case 1: - strlcpy(p, "PARITY;", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "PARITY;"); break; case 2: - strlcpy(p, "TLM/HOW;", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "TLM/HOW;"); break; case 3: - strlcpy(p, "Z-COUNT;", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "Z-COUNT;"); break; case 4: - strlcpy(p, "SUBFRAME 1,2,3;", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "SUBFRAME 1,2,3;"); break; case 5: - strlcpy(p, "SUBFRAME 4,5;", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "SUBFRAME 4,5;"); break; case 6: - strlcpy(p, "UPLOAD BAD;", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "UPLOAD BAD;"); break; case 7: - strlcpy(p, "DATA BAD;", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "DATA BAD;"); break; } - p += strlen(p); - switch (cfgh.health[i] & 0x1F) { case 0: - strlcpy(p, "SIGNAL OK", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "SIGNAL OK"); break; case 0x1C: - strlcpy(p, "SV TEMP OUT", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "SV TEMP OUT"); break; case 0x1D: - strlcpy(p, "SV WILL BE TEMP OUT", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "SV WILL BE TEMP OUT"); break; case 0x1E: break; case 0x1F: - strlcpy(p, "MULTIPLE ERRS", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "MULTIPLE ERRS"); break; default: - strlcpy(p, "TRANSMISSION PROBLEMS", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "TRANSMISSION PROBLEMS"); break; } - strlcat(p, "\"", sizeof(buffer)); - set_var(&parse->kv, buffer, strlen(buffer)+1, RO); + p = ap(buffer, sizeof(buffer), p, "\""); + set_var(&parse->kv, buffer, sizeof(buffer), RO); } } } @@ -4557,16 +4592,16 @@ gps16x_message( if (utc.valid) { - strlcpy(p, "gps_utc_correction=\"", sizeof(buffer)); - p += strlen(p); + p = ap(buffer, sizeof(buffer), p, "gps_utc_correction=\""); mk_utcinfo(p, utc.t0t.wn, utc.WNlsf, utc.DNt, utc.delta_tls, utc.delta_tlsf, BUFFER_SIZE(buffer, p)); - strlcat(p, "\"", BUFFER_SIZE(buffer, p)); + p += strlen(p); + p = ap(buffer, sizeof(buffer), p, "\""); } else { - strlcpy(p, "gps_utc_correction=\"\"", BUFFER_SIZE(buffer, p)); + p = ap(buffer, sizeof(buffer), p, "gps_utc_correction=\"\""); } - set_var(&parse->kv, buffer, strlen(buffer)+1, RO|DEF); + set_var(&parse->kv, buffer, sizeof(buffer), RO|DEF); } break; @@ -4588,9 +4623,9 @@ gps16x_message( snprintf(buffer, sizeof(buffer), "gps_message=\"%s\"", buffer1); } else - strlcpy(buffer, "gps_message=", sizeof(buffer)); + snprintf(buffer, sizeof(buffer), "gps_message="); - set_var(&parse->kv, buffer, strlen(buffer)+1, RO|DEF); + set_var(&parse->kv, buffer, sizeof(buffer), RO|DEF); } break; @@ -4863,7 +4898,7 @@ trimbletaip_event( } else { - if (rtc != strlen(*iv)) + if (rtc != (int)strlen(*iv)) { msyslog(LOG_ERR, "PARSE receiver #%d: trimbletaip_event: failed to send cmd incomplete (%d of %d bytes sent)", CLK_UNIT(parse->peer), rtc, (int)strlen(*iv)); @@ -5394,7 +5429,7 @@ trimbletsip_message( { #ifdef DEBUG if (debug > 2) { - int i; + size_t i; printf("TRIMBLE BAD packet, size %d:\n ", size); for (i = 0; i < size; i++) { @@ -5417,7 +5452,7 @@ trimbletsip_message( #ifdef DEBUG if (debug > 3) { - int i; + size_t i; printf("TRIMBLE packet 0x%02x, size %d:\n ", cmd, size); for (i = 0; i < size; i++) { @@ -5435,7 +5470,7 @@ trimbletsip_message( if (s) { - snprintf(t, BUFFER_SIZE(pbuffer, t), "%s=\"", s->varname); + t = ap(pbuffer, sizeof(pbuffer), t, "%s=\"", s->varname); } else { @@ -5445,45 +5480,41 @@ trimbletsip_message( var_flag = s->varmode; - t += strlen(t); - switch(cmd) { case CMD_RCURTIME: - snprintf(t, BUFFER_SIZE(pbuffer, t), "%f, %d, %f", + t = ap(pbuffer, sizeof(pbuffer), t, "%f, %d, %f", getflt((unsigned char *)&mb(0)), getshort((unsigned char *)&mb(4)), getflt((unsigned char *)&mb(6))); break; case CMD_RBEST4: - strlcpy(t, "mode: ", BUFFER_SIZE(pbuffer, t)); - t += strlen(t); + t = ap(pbuffer, sizeof(pbuffer), t, "mode: "); switch (mb(0) & 0xF) { default: - snprintf(t, BUFFER_SIZE(pbuffer, t), "0x%x", mb(0) & 0x7); + t = ap(pbuffer, sizeof(pbuffer), t, + "0x%x", mb(0) & 0x7); break; case 1: - strlcpy(t, "0D", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "0D"); break; case 3: - strlcpy(t, "2D", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "2D"); break; case 4: - strlcpy(t, "3D", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "3D"); break; } - t += strlen(t); if (mb(0) & 0x10) - strlcpy(t, "-MANUAL, ", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "-MANUAL, "); else - strlcpy(t, "-AUTO, ", BUFFER_SIZE(pbuffer, t)); - t += strlen(t); + t = ap(pbuffer, sizeof(pbuffer), t, "-AUTO, "); - snprintf(t, BUFFER_SIZE(pbuffer, t), "satellites %02d %02d %02d %02d, PDOP %.2f, HDOP %.2f, VDOP %.2f, TDOP %.2f", + t = ap(pbuffer, sizeof(pbuffer), t, "satellites %02d %02d %02d %02d, PDOP %.2f, HDOP %.2f, VDOP %.2f, TDOP %.2f", mb(1), mb(2), mb(3), mb(4), getflt((unsigned char *)&mb(5)), getflt((unsigned char *)&mb(9)), @@ -5493,7 +5524,7 @@ trimbletsip_message( break; case CMD_RVERSION: - snprintf(t, BUFFER_SIZE(pbuffer, t), "%d.%d (%d/%d/%d)", + t = ap(pbuffer, sizeof(pbuffer), t, "%d.%d (%d/%d/%d)", mb(0)&0xff, mb(1)&0xff, 1900+(mb(4)&0xff), mb(2)&0xff, mb(3)&0xff); break; @@ -5516,43 +5547,40 @@ trimbletsip_message( switch (mb(0) & 0xFF) { default: - snprintf(t, BUFFER_SIZE(pbuffer, t), "illegal value 0x%02x", mb(0) & 0xFF); + t = ap(pbuffer, sizeof(pbuffer), t, "illegal value 0x%02x", mb(0) & 0xFF); break; case 0x00: - strlcpy(t, "doing position fixes", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "doing position fixes"); break; case 0x01: - strlcpy(t, "no GPS time yet", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "no GPS time yet"); break; case 0x03: - strlcpy(t, "PDOP too high", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "PDOP too high"); break; case 0x08: - strlcpy(t, "no usable satellites", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "no usable satellites"); break; case 0x09: - strlcpy(t, "only ONE usable satellite", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "only ONE usable satellite"); break; case 0x0A: - strlcpy(t, "only TWO usable satellites", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "only TWO usable satellites"); break; case 0x0B: - strlcpy(t, "only THREE usable satellites", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "only THREE usable satellites"); break; case 0x0C: - strlcpy(t, "the chosen satellite is unusable", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "the chosen satellite is unusable"); break; } - t += strlen(t); - bits = mb(1) & 0xFF; for (i = 0; i < 8; i++) if (bits & (0x1<", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, ""); } } break; case CMD_RSAT1BIAS: - snprintf(t, BUFFER_SIZE(pbuffer, t), "%.1fm %.2fm/s at %.1fs", + t = ap(pbuffer, sizeof(pbuffer), t, "%.1fm %.2fm/s at %.1fs", getflt(&mb(0)), getflt(&mb(4)), getflt(&mb(8))); break; case CMD_RIOOPTIONS: { - snprintf(t, BUFFER_SIZE(pbuffer, t), "%02x %02x %02x %02x", + t = ap(pbuffer, sizeof(pbuffer), t, "%02x %02x %02x %02x", mb(0), mb(1), mb(2), mb(3)); if (mb(0) != TRIM_POS_OPT || mb(2) != TRIM_TIME_OPT) @@ -5644,9 +5669,9 @@ trimbletsip_message( double f = getflt((unsigned char *)&mb(12)); if (f > 0.0) - snprintf(t, BUFFER_SIZE(pbuffer, t), "x= %.1fm, y= %.1fm, z= %.1fm, time_of_fix= %f sec", - x, y, z, - f); + t = ap(pbuffer, sizeof(pbuffer), t, "x= %.1fm, y= %.1fm, z= %.1fm, time_of_fix= %f sec", + x, y, z, + f); else return; } @@ -5659,10 +5684,10 @@ trimbletsip_message( double f = getflt((unsigned char *)&mb(12)); if (f > 0.0) - snprintf(t, BUFFER_SIZE(pbuffer, t), "lat %f %c, long %f %c, alt %.2fm", - ((lat < 0.0) ? (-lat) : (lat))*RTOD, (lat < 0.0 ? 'S' : 'N'), - ((lng < 0.0) ? (-lng) : (lng))*RTOD, (lng < 0.0 ? 'W' : 'E'), - getflt((unsigned char *)&mb(8))); + t = ap(pbuffer, sizeof(pbuffer), t, "lat %f %c, long %f %c, alt %.2fm", + ((lat < 0.0) ? (-lat) : (lat))*RTOD, (lat < 0.0 ? 'S' : 'N'), + ((lng < 0.0) ? (-lng) : (lng))*RTOD, (lng < 0.0 ? 'W' : 'E'), + getflt((unsigned char *)&mb(8))); else return; } @@ -5673,8 +5698,8 @@ trimbletsip_message( double x = getdbl((unsigned char *)&mb(0)); double y = getdbl((unsigned char *)&mb(8)); double z = getdbl((unsigned char *)&mb(16)); - snprintf(t, BUFFER_SIZE(pbuffer, t), "x= %.1fm, y= %.1fm, z= %.1fm", - x, y, z); + t = ap(pbuffer, sizeof(pbuffer), t, "x= %.1fm, y= %.1fm, z= %.1fm", + x, y, z); } break; @@ -5682,7 +5707,7 @@ trimbletsip_message( { double lat = getdbl((unsigned char *)&mb(0)); double lng = getdbl((unsigned char *)&mb(8)); - snprintf(t, BUFFER_SIZE(pbuffer, t), "lat %f %c, lon %f %c, alt %.2fm", + t = ap(pbuffer, sizeof(pbuffer), t, "lat %f %c, lon %f %c, alt %.2fm", ((lat < 0.0) ? (-lat) : (lat))*RTOD, (lat < 0.0 ? 'S' : 'N'), ((lng < 0.0) ? (-lng) : (lng))*RTOD, (lng < 0.0 ? 'W' : 'E'), getdbl((unsigned char *)&mb(16))); @@ -5693,43 +5718,38 @@ trimbletsip_message( { int i, sats; - strlcpy(t, "mode: ", BUFFER_SIZE(pbuffer, t)); - t += strlen(t); + t = ap(pbuffer, sizeof(pbuffer), t, "mode: "); switch (mb(0) & 0x7) { default: - snprintf(t, BUFFER_SIZE(pbuffer, t), "0x%x", mb(0) & 0x7); + t = ap(pbuffer, sizeof(pbuffer), t, "0x%x", mb(0) & 0x7); break; case 3: - strlcpy(t, "2D", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "2D"); break; case 4: - strlcpy(t, "3D", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "3D"); break; } - t += strlen(t); if (mb(0) & 0x8) - strlcpy(t, "-MANUAL, ", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, "-MANUAL, "); else - strlcpy(t, "-AUTO, ", BUFFER_SIZE(pbuffer, t)); - t += strlen(t); + t = ap(pbuffer, sizeof(pbuffer), t, "-AUTO, "); sats = (mb(0)>>4) & 0xF; - snprintf(t, BUFFER_SIZE(pbuffer, t), "PDOP %.2f, HDOP %.2f, VDOP %.2f, TDOP %.2f, %d satellite%s in view: ", + t = ap(pbuffer, sizeof(pbuffer), t, "PDOP %.2f, HDOP %.2f, VDOP %.2f, TDOP %.2f, %d satellite%s in view: ", getflt((unsigned char *)&mb(1)), getflt((unsigned char *)&mb(5)), getflt((unsigned char *)&mb(9)), getflt((unsigned char *)&mb(13)), sats, (sats == 1) ? "" : "s"); - t += strlen(t); for (i=0; i < sats; i++) { - snprintf(t, BUFFER_SIZE(pbuffer, t), "%s%02d", i ? ", " : "", mb(17+i)); - t += strlen(t); + t = ap(pbuffer, sizeof(pbuffer), t, "%s%02d", i ? ", " : "", mb(17+i)); if (tr) tr->ctrack |= (1 << (mb(17+i)-1)); } @@ -5743,52 +5763,46 @@ trimbletsip_message( case CMD_RSTATTRACK: { - snprintf(t-2, BUFFER_SIZE(pbuffer, t-2), "[%02d]=\"", mb(0)); /* add index to var name */ - t += strlen(t); - + t = ap(pbuffer, sizeof(pbuffer), t-2, "[%02d]=\"", mb(0)); /* add index to var name */ if (getflt((unsigned char *)&mb(4)) < 0.0) { - strlcpy(t, "", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, ""); var_flag &= ~DEF; } else { - snprintf(t, BUFFER_SIZE(pbuffer, t), "ch=%d, acq=%s, eph=%d, signal_level= %5.2f, elevation= %5.2f, azimuth= %6.2f", + t = ap(pbuffer, sizeof(pbuffer), t, "ch=%d, acq=%s, eph=%d, signal_level= %5.2f, elevation= %5.2f, azimuth= %6.2f", (mb(1) & 0xFF)>>3, mb(2) ? ((mb(2) == 1) ? "ACQ" : "SRCH") : "NEVER", mb(3), getflt((unsigned char *)&mb(4)), getflt((unsigned char *)&mb(12)) * RTOD, getflt((unsigned char *)&mb(16)) * RTOD); - t += strlen(t); if (mb(20)) { var_flag &= ~DEF; - strlcpy(t, ", OLD", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, ", OLD"); } - t += strlen(t); if (mb(22)) { if (mb(22) == 1) - strlcpy(t, ", BAD PARITY", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, ", BAD PARITY"); else if (mb(22) == 2) - strlcpy(t, ", BAD EPH HEALTH", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, ", BAD EPH HEALTH"); } - t += strlen(t); if (mb(23)) - strlcpy(t, ", collecting data", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, ", collecting data"); } } break; default: - strlcpy(t, "", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t, ""); break; } - t += strlen(t); - strlcpy(t,"\"", BUFFER_SIZE(pbuffer, t)); + t = ap(pbuffer, sizeof(pbuffer), t,"\""); set_var(&parse->kv, pbuffer, sizeof(pbuffer), var_flag); } } diff --git a/ntpd/refclock_pcf.c b/ntpd/refclock_pcf.c index 4379832b4..45b3475c0 100644 --- a/ntpd/refclock_pcf.c +++ b/ntpd/refclock_pcf.c @@ -140,7 +140,7 @@ pcf_poll( pp = peer->procptr; buf[0] = 0; - if (read(pp->io.fd, buf, sizeof(buf)) < sizeof(buf) || buf[0] != 9) { + if (read(pp->io.fd, buf, sizeof(buf)) < (ssize_t)sizeof(buf) || buf[0] != 9) { refclock_report(peer, CEVNT_FAULT); return; } diff --git a/ntpd/refclock_true.c b/ntpd/refclock_true.c index 36ade81c7..7a5c491bb 100644 --- a/ntpd/refclock_true.c +++ b/ntpd/refclock_true.c @@ -215,6 +215,7 @@ struct refclock refclock_true = { #if !defined(__STDC__) # define true_debug (void) #else +NTP_PRINTF(2, 3) static void true_debug(struct peer *peer, const char *fmt, ...) { diff --git a/ntpd/refclock_wwv.c b/ntpd/refclock_wwv.c index 14183b46c..79c0afd5b 100644 --- a/ntpd/refclock_wwv.c +++ b/ntpd/refclock_wwv.c @@ -1338,7 +1338,7 @@ wwv_qrz( if (sp->reach & (1 << AMAX)) sp->count--; if (sp->synmax > ATHR && sp->synsnr > ASNR) { - if (abs(epoch) < AWND * MS) { + if (labs(epoch) < AWND * MS) { sp->reach |= 1; sp->count++; sp->mepoch = sp->lastpos = sp->pos; @@ -1540,14 +1540,14 @@ wwv_endpoc( */ dtemp = (mepoch - zepoch) % WWV_SEC; if (up->status & FGATE) { - if (abs(dtemp) < MAXFREQ * MINAVG) { + if (fabs(dtemp) < MAXFREQ * MINAVG) { up->freq += (dtemp / 2.) / ((mcount - zcount) * FCONST); if (up->freq > MAXFREQ) up->freq = MAXFREQ; else if (up->freq < -MAXFREQ) up->freq = -MAXFREQ; - if (abs(dtemp) < MAXFREQ * MINAVG / 2.) { + if (fabs(dtemp) < MAXFREQ * MINAVG / 2.) { if (avginc < 3) { avginc++; } else { diff --git a/ntpd/refclock_wwvb.c b/ntpd/refclock_wwvb.c index 75897fcc5..8e4fba6ac 100644 --- a/ntpd/refclock_wwvb.c +++ b/ntpd/refclock_wwvb.c @@ -154,7 +154,8 @@ static void wwvb_control (int, const struct refclockstat *, struct refclockstat *, struct peer *); #define WWVB_CONTROL wwvb_control #else -#define WWVB_CONTROL noentry +#define WWVB_CONTROL (void)(*) +noentry #endif /* HAVE_PPSAPI */ /* diff --git a/ntpdate/ntpdate.c b/ntpdate/ntpdate.c index 16569f30b..08edc8be4 100644 --- a/ntpdate/ntpdate.c +++ b/ntpdate/ntpdate.c @@ -751,7 +751,7 @@ receive( */ if (rbufp->recv_length == LEN_PKT_NOMAC) has_mac = 0; - else if (rbufp->recv_length >= LEN_PKT_NOMAC) + else if (rbufp->recv_length >= (int)LEN_PKT_NOMAC) has_mac = 1; else { if (debug) diff --git a/ntpdc/ntpdc.c b/ntpdc/ntpdc.c index 35951841e..ce35bd4e2 100644 --- a/ntpdc/ntpdc.c +++ b/ntpdc/ntpdc.c @@ -96,8 +96,10 @@ static void hostnames (struct parse *, FILE *); static void setdebug (struct parse *, FILE *); static void quit (struct parse *, FILE *); static void version (struct parse *, FILE *); -static void warning (const char *, const char *, const char *); -static void error (const char *, const char *, const char *); +static void warning (const char *, ...) + __attribute__((__format__(__printf__, 1, 2))); +static void error (const char *, ...) + __attribute__((__format__(__printf__, 1, 2))); static u_long getkeyid (const char *); @@ -506,7 +508,7 @@ openhost( sockfd = socket(ai->ai_family, SOCK_DGRAM, 0); if (sockfd == INVALID_SOCKET) { - error("socket", "", ""); + error("socket"); exit(-1); } @@ -517,7 +519,7 @@ openhost( if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &rbufsize, sizeof(int)) == -1) - error("setsockopt", "", ""); + error("setsockopt"); } # endif #endif @@ -528,7 +530,7 @@ openhost( #else if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) == -1) { #endif /* SYS_VXWORKS */ - error("connect", "", ""); + error("connect"); exit(-1); } @@ -551,7 +553,7 @@ sendpkt( ) { if (send(sockfd, xdata, xdatalen, 0) == -1) { - warning("write to %s failed", currenthost, ""); + warning("write to %s failed", currenthost); return -1; } @@ -600,7 +602,7 @@ getresponse( int numrecv; int seq; fd_set fds; - int n; + ssize_t n; int pad; /* @@ -629,7 +631,7 @@ getresponse( n = select(sockfd+1, &fds, (fd_set *)0, (fd_set *)0, &tvo); if (n == -1) { - warning("select fails", "", ""); + warning("select fails"); return -1; } if (n == 0) { @@ -648,7 +650,7 @@ getresponse( printf("Received sequence numbers"); for (n = 0; n <= MAXSEQ; n++) if (haveseq[n]) - printf(" %d,", n); + printf(" %zd,", n); if (lastseq != 999) printf(" last frame received\n"); else @@ -660,7 +662,7 @@ getresponse( n = recv(sockfd, (char *)&rpkt, sizeof(rpkt), 0); if (n == -1) { - warning("read", "", ""); + warning("read"); return -1; } @@ -668,9 +670,9 @@ getresponse( /* * Check for format errors. Bug proofing. */ - if (n < RESP_HEADER_SIZE) { + if (n < (ssize_t)RESP_HEADER_SIZE) { if (debug) - printf("Short (%d byte) packet received\n", n); + printf("Short (%zd byte) packet received\n", n); goto again; } if (INFO_VERSION(rpkt.rm_vn_mode) > NTP_VERSION || @@ -738,8 +740,8 @@ getresponse( if ((size_t)datasize > (n-RESP_HEADER_SIZE)) { if (debug) printf( - "Received items %d, size %d (total %d), data in packet is %lu\n", - items, size, datasize, (u_long)(n-RESP_HEADER_SIZE)); + "Received items %d, size %d (total %d), data in packet is %zu\n", + items, size, datasize, n-RESP_HEADER_SIZE); goto again; } @@ -920,11 +922,11 @@ sendrequest( if (!maclen) { fprintf(stderr, "Key not found\n"); return 1; - } else if (maclen != (info_auth_hashlen + sizeof(keyid_t))) { + } else if (maclen != (int)(info_auth_hashlen + sizeof(keyid_t))) { fprintf(stderr, - "%d octet MAC, %lu expected with %lu octet digest\n", - maclen, (u_long)(info_auth_hashlen + sizeof(keyid_t)), - (u_long)info_auth_hashlen); + "%d octet MAC, %zu expected with %zu octet digest\n", + maclen, (info_auth_hashlen + sizeof(keyid_t)), + info_auth_hashlen); return 1; } return sendpkt(&qpkt, reqsize + maclen); @@ -973,7 +975,7 @@ again: res = select(sockfd+1, &fds, (fd_set *)0, (fd_set *)0, &tvzero); if (res == -1) { - warning("polling select", "", ""); + warning("polling select"); return -1; } else if (res > 0) @@ -1868,34 +1870,44 @@ version( } +static void __attribute__((__format__(__printf__, 1, 0))) +vwarning(const char *fmt, va_list ap) +{ + int serrno = errno; + (void) fprintf(stderr, "%s: ", progname); + vfprintf(stderr, fmt, ap); + (void) fprintf(stderr, ": %s\n", strerror(serrno)); +} + /* * warning - print a warning message */ -static void +static void __attribute__((__format__(__printf__, 1, 2))) warning( const char *fmt, - const char *st1, - const char *st2 + ... ) { - (void) fprintf(stderr, "%s: ", progname); - (void) fprintf(stderr, fmt, st1, st2); - (void) fprintf(stderr, ": "); - perror(""); + va_list ap; + va_start(ap, fmt); + vwarning(fmt, ap); + va_end(ap); } /* * error - print a message and exit */ -static void +static void __attribute__((__format__(__printf__, 1, 2))) error( const char *fmt, - const char *st1, - const char *st2 + ... ) { - warning(fmt, st1, st2); + va_list ap; + va_start(ap, fmt); + vwarning(fmt, ap); + va_end(ap); exit(1); } diff --git a/ntpdc/ntpdc.h b/ntpdc/ntpdc.h index bfc222863..6da4a5cb7 100644 --- a/ntpdc/ntpdc.h +++ b/ntpdc/ntpdc.h @@ -43,7 +43,7 @@ typedef struct { struct parse { char *keyword; arg_v argval[MAXARGS + MOREARGS]; - int nargs; + size_t nargs; }; /* diff --git a/ntpdc/ntpdc_ops.c b/ntpdc/ntpdc_ops.c index b0e7af05b..be8ffa24a 100644 --- a/ntpdc/ntpdc_ops.c +++ b/ntpdc/ntpdc_ops.c @@ -1346,7 +1346,7 @@ again: sendsize = v4sizeof(struct conf_peer); items = 1; - while (pcmd->nargs > items) { + while (pcmd->nargs > (size_t)items) { if (STREQ(pcmd->argval[items].string, "prefer")) flags |= CONF_FLAG_PREFER; else if (STREQ(pcmd->argval[items].string, "burst")) @@ -1571,7 +1571,7 @@ doset( sys.flags = 0; res = 0; - for (items = 0; items < pcmd->nargs; items++) { + for (items = 0; (size_t)items < pcmd->nargs; items++) { if (STREQ(pcmd->argval[items].string, "auth")) sys.flags |= SYS_FLAG_AUTH; else if (STREQ(pcmd->argval[items].string, "bclient")) @@ -1833,7 +1833,7 @@ do_restrict( u_int32 num; u_long bit; int i; - int res; + size_t res; int err; int sendsize; @@ -2095,7 +2095,7 @@ reset( int itemsize; char *dummy; int i; - int res; + size_t res; int err; err = 0; @@ -2262,7 +2262,7 @@ do_trustkey( ) { u_long keyids[MAXARGS]; - int i; + size_t i; int items; int itemsize; char *dummy; @@ -3055,7 +3055,7 @@ iflist( int res ) { - static char *actions = "?.+-"; + static const char *actions = "?.+-"; sockaddr_u saddr; if (res != 0) diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index 5460f80fc..a33b4ccc8 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -269,7 +269,7 @@ char flash2[] = " .+* "; /* flash decode for version 2 */ char flash3[] = " x.-+#*o"; /* flash decode for peer status version 3 */ struct varlist { - char *name; + const char *name; char *value; } g_varlist[MAXLIST] = { { 0, 0 } }; @@ -330,6 +330,7 @@ typedef struct var_display_collection_tag { l_fp lfp; /* NTP_LFP */ } v; /* retrieved value */ } vdc; +#define VDC_INIT(a, b, c) { .tag = a, .display = b, .type = c } /* * other local function prototypes @@ -362,7 +363,7 @@ static mru ** hash_table; * qsort comparison function table for mrulist(). The first two * entries are NULL because they are handled without qsort(). */ -const static qsort_cmp mru_qcmp_table[MRUSORT_MAX] = { +static const qsort_cmp mru_qcmp_table[MRUSORT_MAX] = { NULL, /* MRUSORT_DEF unused */ NULL, /* MRUSORT_R_DEF unused */ &qcmp_mru_avgint, /* MRUSORT_AVGINT */ @@ -477,7 +478,7 @@ dormvlist( (void) fprintf(stderr, "Variable `%s' not found\n", name); } else { - free((void *)vl->name); + free((void *)(intptr_t)vl->name); if (vl->value != 0) free(vl->value); for ( ; (vl+1) < (g_varlist + MAXLIST) @@ -502,7 +503,7 @@ doclearvlist( register struct varlist *vl; for (vl = vlist; vl < vlist + MAXLIST && vl->name != 0; vl++) { - free((void *)vl->name); + free((void *)(intptr_t)vl->name); vl->name = 0; if (vl->value != 0) { free(vl->value); @@ -2192,7 +2193,7 @@ fetch_nonce( return FALSE; } - if (rsize <= sizeof(nonce_eq) - 1 || + if ((size_t)rsize <= sizeof(nonce_eq) - 1 || strncmp(rdata, nonce_eq, sizeof(nonce_eq) - 1)) { fprintf(stderr, "unexpected nonce response format: %.*s\n", rsize, rdata); @@ -2935,7 +2936,7 @@ mrulist( double flstint; int avgint; int lstint; - int i; + size_t i; order = MRUSORT_DEF; parms_buf[0] = '\0'; @@ -3041,7 +3042,7 @@ mrulist( LFPTOD(&interval, favgint); favgint /= recent->count; avgint = (int)(favgint + 0.5); - fprintf(fp, "%6d %6d %4hx %c %d %d %6d %5hu %s\n", + fprintf(fp, "%6d %6d %4hx %c %d %d %6d %5u %s\n", lstint, avgint, recent->rs, (RES_KOD & recent->rs) ? 'K' @@ -3179,7 +3180,6 @@ ifstats( char * tag; char * val; int fields; - u_int ifnum; u_int ui; ifstats_row row; int comprende; @@ -3198,7 +3198,6 @@ ifstats( ZERO(row); fields = 0; - ifnum = 0; ui = 0; while (nextvar(&dsize, &datap, &tag, &val)) { if (debug > 1) @@ -3396,7 +3395,6 @@ reslist( char * tag; char * val; int fields; - u_int idx; u_int ui; reslist_row row; int comprende; @@ -3415,7 +3413,6 @@ reslist( ZERO(row); fields = 0; - idx = 0; ui = 0; while (nextvar(&dsize, &datap, &tag, &val)) { if (debug > 1) @@ -3656,19 +3653,19 @@ sysstats( ) { static vdc sysstats_vdc[] = { - { "ss_uptime", "uptime: ", NTP_STR }, - { "ss_reset", "sysstats reset: ", NTP_STR }, - { "ss_received", "packets received: ", NTP_STR }, - { "ss_thisver", "current version: ", NTP_STR }, - { "ss_oldver", "older version: ", NTP_STR }, - { "ss_badformat", "bad length or format: ", NTP_STR }, - { "ss_badauth", "authentication failed:", NTP_STR }, - { "ss_declined", "declined: ", NTP_STR }, - { "ss_restricted", "restricted: ", NTP_STR }, - { "ss_limited", "rate limited: ", NTP_STR }, - { "ss_kodsent", "KoD responses: ", NTP_STR }, - { "ss_processed", "processed for time: ", NTP_STR }, - { NULL, NULL, 0 } + VDC_INIT("ss_uptime", "uptime: ", NTP_STR), + VDC_INIT("ss_reset", "sysstats reset: ", NTP_STR), + VDC_INIT("ss_received", "packets received: ", NTP_STR), + VDC_INIT("ss_thisver", "current version: ", NTP_STR), + VDC_INIT("ss_oldver", "older version: ", NTP_STR), + VDC_INIT("ss_badformat", "bad length or format: ", NTP_STR), + VDC_INIT("ss_badauth", "authentication failed:", NTP_STR), + VDC_INIT("ss_declined", "declined: ", NTP_STR), + VDC_INIT("ss_restricted", "restricted: ", NTP_STR), + VDC_INIT("ss_limited", "rate limited: ", NTP_STR), + VDC_INIT("ss_kodsent", "KoD responses: ", NTP_STR), + VDC_INIT("ss_processed", "processed for time: ", NTP_STR), + VDC_INIT(NULL, NULL, 0) }; collect_display_vdc(0, sysstats_vdc, FALSE, fp); @@ -3685,21 +3682,21 @@ sysinfo( ) { static vdc sysinfo_vdc[] = { - { "peeradr", "system peer: ", NTP_ADP }, - { "peermode", "system peer mode: ", NTP_MODE }, - { "leap", "leap indicator: ", NTP_2BIT }, - { "stratum", "stratum: ", NTP_STR }, - { "precision", "log2 precision: ", NTP_STR }, - { "rootdelay", "root delay: ", NTP_STR }, - { "rootdisp", "root dispersion: ", NTP_STR }, - { "refid", "reference ID: ", NTP_STR }, - { "reftime", "reference time: ", NTP_LFP }, - { "sys_jitter", "system jitter: ", NTP_STR }, - { "clk_jitter", "clock jitter: ", NTP_STR }, - { "clk_wander", "clock wander: ", NTP_STR }, - { "bcastdelay", "broadcast delay: ", NTP_STR }, - { "authdelay", "symm. auth. delay:", NTP_STR }, - { NULL, NULL, 0 } + VDC_INIT("peeradr", "system peer: ", NTP_ADP), + VDC_INIT("peermode", "system peer mode: ", NTP_MODE), + VDC_INIT("leap", "leap indicator: ", NTP_2BIT), + VDC_INIT("stratum", "stratum: ", NTP_STR), + VDC_INIT("precision", "log2 precision: ", NTP_STR), + VDC_INIT("rootdelay", "root delay: ", NTP_STR), + VDC_INIT("rootdisp", "root dispersion: ", NTP_STR), + VDC_INIT("refid", "reference ID: ", NTP_STR), + VDC_INIT("reftime", "reference time: ", NTP_LFP), + VDC_INIT("sys_jitter", "system jitter: ", NTP_STR), + VDC_INIT("clk_jitter", "clock jitter: ", NTP_STR), + VDC_INIT("clk_wander", "clock wander: ", NTP_STR), + VDC_INIT("bcastdelay", "broadcast delay: ", NTP_STR), + VDC_INIT("authdelay", "symm. auth. delay:", NTP_STR), + VDC_INIT(NULL, NULL, 0) }; collect_display_vdc(0, sysinfo_vdc, TRUE, fp); @@ -3716,23 +3713,23 @@ kerninfo( ) { static vdc kerninfo_vdc[] = { - { "koffset", "pll offset: ", NTP_STR }, - { "kfreq", "pll frequency: ", NTP_STR }, - { "kmaxerr", "maximum error: ", NTP_STR }, - { "kesterr", "estimated error: ", NTP_STR }, - { "kstflags", "kernel status: ", NTP_STR }, - { "ktimeconst", "pll time constant: ", NTP_STR }, - { "kprecis", "precision: ", NTP_STR }, - { "kfreqtol", "frequency tolerance: ", NTP_STR }, - { "kppsfreq", "pps frequency: ", NTP_STR }, - { "kppsstab", "pps stability: ", NTP_STR }, - { "kppsjitter", "pps jitter: ", NTP_STR }, - { "kppscalibdur", "calibration interval ", NTP_STR }, - { "kppscalibs", "calibration cycles: ", NTP_STR }, - { "kppsjitexc", "jitter exceeded: ", NTP_STR }, - { "kppsstbexc", "stability exceeded: ", NTP_STR }, - { "kppscaliberrs", "calibration errors: ", NTP_STR }, - { NULL, NULL, 0 } + VDC_INIT("koffset", "pll offset: ", NTP_STR), + VDC_INIT("kfreq", "pll frequency: ", NTP_STR), + VDC_INIT("kmaxerr", "maximum error: ", NTP_STR), + VDC_INIT("kesterr", "estimated error: ", NTP_STR), + VDC_INIT("kstflags", "kernel status: ", NTP_STR), + VDC_INIT("ktimeconst", "pll time constant: ", NTP_STR), + VDC_INIT("kprecis", "precision: ", NTP_STR), + VDC_INIT("kfreqtol", "frequency tolerance: ", NTP_STR), + VDC_INIT("kppsfreq", "pps frequency: ", NTP_STR), + VDC_INIT("kppsstab", "pps stability: ", NTP_STR), + VDC_INIT("kppsjitter", "pps jitter: ", NTP_STR), + VDC_INIT("kppscalibdur", "calibration interval ", NTP_STR), + VDC_INIT("kppscalibs", "calibration cycles: ", NTP_STR), + VDC_INIT("kppsjitexc", "jitter exceeded: ", NTP_STR), + VDC_INIT("kppsstbexc", "stability exceeded: ", NTP_STR), + VDC_INIT("kppscaliberrs", "calibration errors: ", NTP_STR), + VDC_INIT(NULL, NULL, 0) }; collect_display_vdc(0, kerninfo_vdc, TRUE, fp); @@ -3749,15 +3746,15 @@ monstats( ) { static vdc monstats_vdc[] = { - { "mru_enabled", "enabled: ", NTP_STR }, - { "mru_depth", "addresses: ", NTP_STR }, - { "mru_deepest", "peak addresses: ", NTP_STR }, - { "mru_maxdepth", "maximum addresses: ", NTP_STR }, - { "mru_mindepth", "reclaim above count:", NTP_STR }, - { "mru_maxage", "reclaim older than: ", NTP_STR }, - { "mru_mem", "kilobytes: ", NTP_STR }, - { "mru_maxmem", "maximum kilobytes: ", NTP_STR }, - { NULL, NULL, 0 } + VDC_INIT("mru_enabled", "enabled: ", NTP_STR), + VDC_INIT("mru_depth", "addresses: ", NTP_STR), + VDC_INIT("mru_deepest", "peak addresses: ", NTP_STR), + VDC_INIT("mru_maxdepth", "maximum addresses: ", NTP_STR), + VDC_INIT("mru_mindepth", "reclaim above count:", NTP_STR), + VDC_INIT("mru_maxage", "reclaim older than: ", NTP_STR), + VDC_INIT("mru_mem", "kilobytes: ", NTP_STR), + VDC_INIT("mru_maxmem", "maximum kilobytes: ", NTP_STR), + VDC_INIT(NULL, NULL, 0) }; collect_display_vdc(0, monstats_vdc, FALSE, fp); @@ -3774,19 +3771,19 @@ iostats( ) { static vdc iostats_vdc[] = { - { "iostats_reset", "time since reset: ", NTP_STR }, - { "total_rbuf", "receive buffers: ", NTP_STR }, - { "free_rbuf", "free receive buffers: ", NTP_STR }, - { "used_rbuf", "used receive buffers: ", NTP_STR }, - { "rbuf_lowater", "low water refills: ", NTP_STR }, - { "io_dropped", "dropped packets: ", NTP_STR }, - { "io_ignored", "ignored packets: ", NTP_STR }, - { "io_received", "received packets: ", NTP_STR }, - { "io_sent", "packets sent: ", NTP_STR }, - { "io_sendfailed", "packet send failures: ", NTP_STR }, - { "io_wakeups", "input wakeups: ", NTP_STR }, - { "io_goodwakeups", "useful input wakeups: ", NTP_STR }, - { NULL, NULL, 0 } + VDC_INIT("iostats_reset", "time since reset: ", NTP_STR), + VDC_INIT("total_rbuf", "receive buffers: ", NTP_STR), + VDC_INIT("free_rbuf", "free receive buffers: ", NTP_STR), + VDC_INIT("used_rbuf", "used receive buffers: ", NTP_STR), + VDC_INIT("rbuf_lowater", "low water refills: ", NTP_STR), + VDC_INIT("io_dropped", "dropped packets: ", NTP_STR), + VDC_INIT("io_ignored", "ignored packets: ", NTP_STR), + VDC_INIT("io_received", "received packets: ", NTP_STR), + VDC_INIT("io_sent", "packets sent: ", NTP_STR), + VDC_INIT("io_sendfailed", "packet send failures: ", NTP_STR), + VDC_INIT("io_wakeups", "input wakeups: ", NTP_STR), + VDC_INIT("io_goodwakeups", "useful input wakeups: ", NTP_STR), + VDC_INIT(NULL, NULL, 0) }; collect_display_vdc(0, iostats_vdc, FALSE, fp); @@ -3803,10 +3800,10 @@ timerstats( ) { static vdc timerstats_vdc[] = { - { "timerstats_reset", "time since reset: ", NTP_STR }, - { "timer_overruns", "timer overruns: ", NTP_STR }, - { "timer_xmts", "calls to transmit: ", NTP_STR }, - { NULL, NULL, 0 } + VDC_INIT("timerstats_reset", "time since reset: ", NTP_STR), + VDC_INIT("timer_overruns", "timer overruns: ", NTP_STR), + VDC_INIT("timer_xmts", "calls to transmit: ", NTP_STR), + VDC_INIT(NULL, NULL, 0) }; collect_display_vdc(0, timerstats_vdc, FALSE, fp); @@ -3823,16 +3820,16 @@ authinfo( ) { static vdc authinfo_vdc[] = { - { "authreset", "time since reset:", NTP_STR }, - { "authkeys", "stored keys: ", NTP_STR }, - { "authfreek", "free keys: ", NTP_STR }, - { "authklookups", "key lookups: ", NTP_STR }, - { "authknotfound", "keys not found: ", NTP_STR }, - { "authkuncached", "uncached keys: ", NTP_STR }, - { "authkexpired", "expired keys: ", NTP_STR }, - { "authencrypts", "encryptions: ", NTP_STR }, - { "authdecrypts", "decryptions: ", NTP_STR }, - { NULL, NULL, 0 } + VDC_INIT("authreset", "time since reset:", NTP_STR), + VDC_INIT("authkeys", "stored keys: ", NTP_STR), + VDC_INIT("authfreek", "free keys: ", NTP_STR), + VDC_INIT("authklookups", "key lookups: ", NTP_STR), + VDC_INIT("authknotfound", "keys not found: ", NTP_STR), + VDC_INIT("authkuncached", "uncached keys: ", NTP_STR), + VDC_INIT("authkexpired", "expired keys: ", NTP_STR), + VDC_INIT("authencrypts", "encryptions: ", NTP_STR), + VDC_INIT("authdecrypts", "decryptions: ", NTP_STR), + VDC_INIT(NULL, NULL, 0) }; collect_display_vdc(0, authinfo_vdc, FALSE, fp); @@ -3849,20 +3846,20 @@ pstats( ) { static vdc pstats_vdc[] = { - { "src", "remote host: ", NTP_ADD }, - { "dst", "local address: ", NTP_ADD }, - { "timerec", "time last received: ", NTP_STR }, - { "timer", "time until next send:", NTP_STR }, - { "timereach", "reachability change: ", NTP_STR }, - { "sent", "packets sent: ", NTP_STR }, - { "received", "packets received: ", NTP_STR }, - { "badauth", "bad authentication: ", NTP_STR }, - { "bogusorg", "bogus origin: ", NTP_STR }, - { "oldpkt", "duplicate: ", NTP_STR }, - { "seldisp", "bad dispersion: ", NTP_STR }, - { "selbroken", "bad reference time: ", NTP_STR }, - { "candidate", "candidate order: ", NTP_STR }, - { NULL, NULL, 0 } + VDC_INIT("src", "remote host: ", NTP_ADD), + VDC_INIT("dst", "local address: ", NTP_ADD), + VDC_INIT("timerec", "time last received: ", NTP_STR), + VDC_INIT("timer", "time until next send:", NTP_STR), + VDC_INIT("timereach", "reachability change: ", NTP_STR), + VDC_INIT("sent", "packets sent: ", NTP_STR), + VDC_INIT("received", "packets received: ", NTP_STR), + VDC_INIT("badauth", "bad authentication: ", NTP_STR), + VDC_INIT("bogusorg", "bogus origin: ", NTP_STR), + VDC_INIT("oldpkt", "duplicate: ", NTP_STR), + VDC_INIT("seldisp", "bad dispersion: ", NTP_STR), + VDC_INIT("selbroken", "bad reference time: ", NTP_STR), + VDC_INIT("candidate", "candidate order: ", NTP_STR), + VDC_INIT(NULL, NULL, 0) }; associd_t associd; @@ -3872,4 +3869,3 @@ pstats( collect_display_vdc(associd, pstats_vdc, TRUE, fp); } - diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 2ffdfc7be..90cae41b1 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -201,8 +201,10 @@ static void raw (struct parse *, FILE *); static void cooked (struct parse *, FILE *); static void authenticate (struct parse *, FILE *); static void ntpversion (struct parse *, FILE *); -static void warning (const char *, const char *, const char *); -static void error (const char *, const char *, const char *); +static void warning (const char *, ...) + __attribute__((__format__(__printf__, 1, 2))); +static void error (const char *, ...) + __attribute__((__format__(__printf__, 1, 2))); static u_long getkeyid (const char *); static void atoascii (const char *, size_t, char *, size_t); static void cookedprint (int, int, const char *, int, int, FILE *); @@ -315,7 +317,7 @@ struct sock_timeval tvsout = { DEFSTIMEOUT, 0 };/* secondary time out */ l_fp delay_time; /* delay time */ char currenthost[LENHOSTNAME]; /* current host name */ int currenthostisnum; /* is prior text from IP? */ -struct sockaddr_in hostaddr = { 0 }; /* host address */ +struct sockaddr_in hostaddr; /* host address */ int showhostnames = 1; /* show host names by default */ int wideremote = 0; /* show wide remote names? */ @@ -678,7 +680,7 @@ openhost( sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if (sockfd == INVALID_SOCKET) { - error("socket", "", ""); + error("socket"); freeaddrinfo(ai); return 0; } @@ -689,7 +691,7 @@ openhost( { int rbufsize = DATASIZE + 2048; /* 2K for slop */ if (setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &rbufsize, sizeof(int)) == -1) - error("setsockopt", "", ""); + error("setsockopt"); } # endif #endif @@ -703,7 +705,7 @@ openhost( ai->ai_addrlen) == -1) #endif /* SYS_VXWORKS */ { - error("connect", "", ""); + error("connect"); freeaddrinfo(ai); return 0; } @@ -761,10 +763,10 @@ sendpkt( ) { if (debug >= 3) - printf("Sending %lu octets\n", (u_long)xdatalen); + printf("Sending %zu octets\n", xdatalen); if (send(sockfd, xdata, (size_t)xdatalen, 0) == -1) { - warning("write to %s failed", currenthost, ""); + warning("write to %s failed", currenthost); return -1; } @@ -835,7 +837,7 @@ getresponse( n = select(sockfd + 1, &fds, NULL, NULL, &tvo); if (n == -1) { - warning("select fails", "", ""); + warning("select fails"); return -1; } if (n == 0) { @@ -874,7 +876,7 @@ getresponse( n = recv(sockfd, (char *)&rpkt, sizeof(rpkt), 0); if (n == -1) { - warning("read", "", ""); + warning("read"); return -1; } @@ -886,7 +888,7 @@ getresponse( /* * Check for format errors. Bug proofing. */ - if (n < CTL_HEADER_LEN) { + if (n < (int)CTL_HEADER_LEN) { if (debug) printf("Short (%d byte) packet received\n", n); continue; @@ -994,7 +996,7 @@ getresponse( shouldbesize = (shouldbesize + 7) & ~7; maclen = n - shouldbesize; - if (maclen >= MIN_MAC_LEN) { + if (maclen >= (int)MIN_MAC_LEN) { printf( "Packet shows signs of authentication (total %d, data %d, mac %d)\n", n, shouldbesize, maclen); @@ -1226,9 +1228,9 @@ sendrequest( return 1; } else if ((size_t)maclen != (info_auth_hashlen + sizeof(keyid_t))) { fprintf(stderr, - "%d octet MAC, %lu expected with %lu octet digest\n", - maclen, (u_long)(info_auth_hashlen + sizeof(keyid_t)), - (u_long)info_auth_hashlen); + "%d octet MAC, %zu expected with %zu octet digest\n", + maclen, (info_auth_hashlen + sizeof(keyid_t)), + info_auth_hashlen); return 1; } @@ -2620,37 +2622,46 @@ ntpversion( } +static void __attribute__((__format__(__printf__, 1, 0))) +vwarning(const char *fmt, va_list ap) +{ + int serrno = errno; + (void) fprintf(stderr, "%s: ", progname); + vfprintf(stderr, fmt, ap); + (void) fprintf(stderr, ": %s", strerror(serrno)); +} + /* * warning - print a warning message */ -static void +static void __attribute__((__format__(__printf__, 1, 2))) warning( const char *fmt, - const char *st1, - const char *st2 + ... ) { - (void) fprintf(stderr, "%s: ", progname); - (void) fprintf(stderr, fmt, st1, st2); - (void) fprintf(stderr, ": "); - perror(""); + va_list ap; + va_start(ap, fmt); + vwarning(fmt, ap); + va_end(ap); } /* * error - print a message and exit */ -static void +static void __attribute__((__format__(__printf__, 1, 2))) error( const char *fmt, - const char *st1, - const char *st2 + ... ) { - warning(fmt, st1, st2); + va_list ap; + va_start(ap, fmt); + vwarning(fmt, ap); + va_end(ap); exit(1); } - /* * getkeyid - prompt the user for a keyid to use */ @@ -2900,7 +2911,7 @@ nextvar( srclen = strcspn(cp, ",=\r\n"); srclen = min(srclen, (size_t)(cpend - cp)); len = srclen; - while (len > 0 && isspace(cp[len - 1])) + while (len > 0 && isspace((unsigned char)cp[len - 1])) len--; if (len > 0) memcpy(name, cp, len); @@ -2924,7 +2935,7 @@ nextvar( * So far, so good. Copy out the value */ cp++; /* past '=' */ - while (cp < cpend && (isspace(*cp) && *cp != '\r' && *cp != '\n')) + while (cp < cpend && (isspace((unsigned char)*cp) && *cp != '\r' && *cp != '\n')) cp++; np = cp; if ('"' == *np) { @@ -2945,7 +2956,7 @@ nextvar( /* * Trim off any trailing whitespace */ - while (len > 0 && isspace(value[len - 1])) + while (len > 0 && isspace((unsigned char)value[len - 1])) len--; value[len] = '\0'; @@ -3028,7 +3039,7 @@ rawprint( */ if (cp == (cpend - 1) || *(cp + 1) != '\n') makeascii(1, cp, fp); - } else if (isspace(*cp) || isprint(*cp)) + } else if (isspace((unsigned char)*cp) || isprint((unsigned char)*cp)) putc(*cp, fp); else makeascii(1, cp, fp); @@ -3176,7 +3187,7 @@ tstflags( *cp++ = ' '; cb--; } - for (i = 0; i < COUNTOF(tstflagnames); i++) { + for (i = 0; i < (int)COUNTOF(tstflagnames); i++) { if (val & 0x1) { snprintf(cp, cb, "%s%s", sep, tstflagnames[i]); diff --git a/ntpq/ntpq.h b/ntpq/ntpq.h index ec2bcb98d..2575b885c 100644 --- a/ntpq/ntpq.h +++ b/ntpq/ntpq.h @@ -79,7 +79,7 @@ typedef union { struct parse { const char *keyword; arg_v argval[MAXARGS]; - int nargs; + size_t nargs; }; /* diff --git a/ntpsnmpd/netsnmp_daemonize.c b/ntpsnmpd/netsnmp_daemonize.c index 969caa0db..4311bac09 100644 --- a/ntpsnmpd/netsnmp_daemonize.c +++ b/ntpsnmpd/netsnmp_daemonize.c @@ -40,6 +40,7 @@ SOFTWARE. #undef PACKAGE_NAME #undef PACKAGE_STRING #undef PACKAGE_TARNAME +#undef PACKAGE_URL #undef PACKAGE_VERSION #include diff --git a/ntpsnmpd/ntp_snmp.h b/ntpsnmpd/ntp_snmp.h index 1e0499d05..b6057582c 100644 --- a/ntpsnmpd/ntp_snmp.h +++ b/ntpsnmpd/ntp_snmp.h @@ -26,6 +26,9 @@ #ifdef PACKAGE_TARNAME # undef PACKAGE_TARNAME #endif +#ifdef PACKAGE_URL +# undef PACKAGE_URL +#endif #ifdef PACKAGE_VERSION # undef PACKAGE_VERSION #endif diff --git a/sntp/crypto.c b/sntp/crypto.c index aa8d91dd2..b178f8c2e 100644 --- a/sntp/crypto.c +++ b/sntp/crypto.c @@ -3,7 +3,7 @@ #include struct key *key_ptr; -int key_cnt = 0; +size_t key_cnt = 0; int make_mac( @@ -51,7 +51,7 @@ auth_md5( int authentic; char digest[20]; - if (mac_size > sizeof(digest)) + if (mac_size > (int)sizeof(digest)) return 0; hash_len = make_mac(pkt_data, pkt_size, sizeof(digest), cmp_key, digest); diff --git a/sntp/libopts/autoopts.h b/sntp/libopts/autoopts.h index ac0a199bf..e14f174a9 100644 --- a/sntp/libopts/autoopts.h +++ b/sntp/libopts/autoopts.h @@ -258,7 +258,7 @@ typedef struct { #define AGALOC(c, w) ao_malloc((size_t)c) #define AGREALOC(p, c, w) ao_realloc((void*)p, (size_t)c) -#define AGFREE(_p) free((void *)_p) +#define AGFREE(p) free((void *)(intptr_t)p) #define AGDUPSTR(p, s, w) (p = ao_strdup(s)) static void * @@ -452,7 +452,7 @@ typedef enum { AOFLAG_TABLE } ao_flags_t; #undef _aof_ static char const zNil[] = ""; -static arg_types_t argTypes = { NULL }; +static arg_types_t argTypes = { .pzStr = NULL }; static char line_fmt_buf[32]; static bool displayEnum = false; static char const pkgdatadir_default[] = PKGDATADIR; diff --git a/sntp/libopts/autoopts/options.h b/sntp/libopts/autoopts/options.h index 0d6f2c371..32397eb9a 100644 --- a/sntp/libopts/autoopts/options.h +++ b/sntp/libopts/autoopts/options.h @@ -600,9 +600,17 @@ struct options { char * pzCurOpt; ///< current option text /// Public, the full path of the program +#if AUTOOPTS_INTERNAL + char const * pzProgPath; +#else char const * const pzProgPath; +#endif /// Public, the name of the executable, without any path +#if AUTOOPTS_INTERNAL + char const * pzProgName; +#else char const * const pzProgName; +#endif /// Public, the upper-cased, shell variable syntax-ed program name char const * const pzPROGNAME; /// the name of the "rc file" (configuration file) @@ -1222,7 +1230,7 @@ extern void optionResetOpt(tOptions*, tOptDesc*); extern void optionSetMembers(tOptions*, tOptDesc*, char const * const *, unsigned int); -extern void optionShowRange(tOptions*, tOptDesc*, void *, int); +extern void optionShowRange(tOptions*, tOptDesc*, const void *, int); extern void optionStackArg(tOptions*, tOptDesc*); diff --git a/sntp/libopts/configfile.c b/sntp/libopts/configfile.c index d4bc4fea2..040944635 100644 --- a/sntp/libopts/configfile.c +++ b/sntp/libopts/configfile.c @@ -184,7 +184,7 @@ 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); + void ** poptv = (void**)(intptr_t)(argl->apzArgs); if (argct == 0) { errno = ENOENT; @@ -266,7 +266,7 @@ optionFindNextValue(const tOptDesc * odesc, const tOptionValue * pPrevVal, else do { tArgList* argl = odesc->optCookie; int ct = argl->useCt; - void** poptv = (void**)argl->apzArgs; + void** poptv = (void**)(intptr_t)argl->apzArgs; while (--ct >= 0) { tOptionValue* pOV = *(poptv++); @@ -326,7 +326,7 @@ optionGetValue(tOptionValue const * oov, char const * vname) if (arg_list->useCt > 0) { int ct = arg_list->useCt; - void ** ovlist = (void**)(arg_list->apzArgs); + void ** ovlist = (void**)(intptr_t)(arg_list->apzArgs); if (vname == NULL) { res = (tOptionValue*)*ovlist; @@ -385,7 +385,7 @@ 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); + void ** o_list = (void**)(intptr_t)(arg_list->apzArgs); while (ct-- > 0) { tOptionValue * nov = *(o_list++); @@ -931,7 +931,7 @@ handle_struct(tOptions * opts, tOptState * ost, char * txt, int dir) switch (*txt) { case ' ': case '\t': - txt = (void *)parse_attrs( + txt = (void *)(intptr_t)parse_attrs( opts, SPN_WHITESPACE_CHARS(txt), &mode, &valu); if (txt == NULL) return txt; @@ -1138,7 +1138,7 @@ optionFileLoad(tOptions * opts, char const * prog) */ { char const ** pp = - (char const **)(void *)&(opts->pzProgName); + (char const **)(void *)(intptr_t)&(opts->pzProgName); *pp = prog; } diff --git a/sntp/libopts/enum.c b/sntp/libopts/enum.c index 299ffb12e..3515e6621 100644 --- a/sntp/libopts/enum.c +++ b/sntp/libopts/enum.c @@ -189,11 +189,11 @@ 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((const char*)name); uintptr_t idx; if (IS_DEC_DIGIT_CHAR(*name)) { - char * pz = (char *)(void *)name; + char * pz = (char *)(void *)(intptr_t)name; unsigned long val = strtoul(pz, &pz, 0); if ((*pz == NUL) && (val < name_ct)) return (uintptr_t)val; @@ -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((char*)(intptr_t)paz_names[idx], (char*)(intptr_t)name, len) == 0) { if (paz_names[idx][len] == NUL) return idx; /* full match */ @@ -253,7 +253,7 @@ find_name(char const * name, tOptions * pOpts, tOptDesc * pOD, char const * optionKeywordName(tOptDesc * pOD, unsigned int enum_val) { - tOptDesc od = { 0 }; + tOptDesc od = { .optIndex = 0 }; od.optArg.argEnum = enum_val; (*(pOD->pOptProc))(OPTPROC_RETURN_VALNAME, &od ); @@ -521,7 +521,7 @@ optionMemberList(tOptDesc * od) uintptr_t sv = od->optArg.argIntptr; char * res; (*(od->pOptProc))(OPTPROC_RETURN_VALNAME, od); - res = (void *)od->optArg.argString; + res = (void *)(intptr_t)od->optArg.argString; od->optArg.argIntptr = sv; return res; } diff --git a/sntp/libopts/file.c b/sntp/libopts/file.c index ec740c5d3..d5fdb4a98 100644 --- a/sntp/libopts/file.c +++ b/sntp/libopts/file.c @@ -107,7 +107,7 @@ open_file_fd(tOptions * pOpts, tOptDesc * pOD, tuFileMode mode) /* NOTREACHED */ if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0) - pOD->optCookie = (void *)pOD->optArg.argString; + pOD->optCookie = (void *)(intptr_t)pOD->optArg.argString; else AGDUPSTR(pOD->optCookie, pOD->optArg.argString, "file name"); @@ -131,7 +131,7 @@ fopen_file_fp(tOptions * pOpts, tOptDesc * pOD, tuFileMode mode) /* NOTREACHED */ if ((pOD->fOptState & OPTST_ALLOC_ARG) != 0) - pOD->optCookie = (void *)pOD->optArg.argString; + pOD->optCookie = (void *)(intptr_t)pOD->optArg.argString; else AGDUPSTR(pOD->optCookie, pOD->optArg.argString, "file name"); diff --git a/sntp/libopts/find.c b/sntp/libopts/find.c index 1ec02e5f6..8d4789628 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 = (char *)(intptr_t)p; return res; default: @@ -711,7 +711,7 @@ find_opt(tOptions * opts, tOptState * o_st) * strip off the "const" quality of the "default_opt" field. */ while (*(++pz) == '-') ; - def_opt = (void *)&(opts->specOptIdx.default_opt); + def_opt = (void *)(intptr_t)&(opts->specOptIdx.default_opt); def = *def_opt; *def_opt = NO_EQUIVALENT; res = opt_find_long(opts, pz, o_st); diff --git a/sntp/libopts/init.c b/sntp/libopts/init.c index e038ed74e..937452812 100644 --- a/sntp/libopts/init.c +++ b/sntp/libopts/init.c @@ -101,20 +101,17 @@ 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); if (pz != NULL) - *pp = pz+1; + opts->pzProgName = pz+1; else - *pp = pname; + opts->pzProgName = pname; - pz = pathfind(getenv("PATH"), (char *)pname, "rx"); + pz = pathfind(getenv("PATH"), (char *)(intptr_t)pname, "rx"); if (pz != NULL) - pname = (void *)pz; + pname = (void *)(intptr_t)pz; - pp = (char const **)(void **)&(opts->pzProgPath); - *pp = pname; + opts->pzProgPath = pname; /* * when comparing long names, these are equivalent diff --git a/sntp/libopts/load.c b/sntp/libopts/load.c index 5c29d96ec..065449255 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"), (char*)(intptr_t)prg_path, "rx"); if (path == NULL) return false; diff --git a/sntp/libopts/makeshell.c b/sntp/libopts/makeshell.c index a0bfcacca..baef8fcb5 100644 --- a/sntp/libopts/makeshell.c +++ b/sntp/libopts/makeshell.c @@ -396,13 +396,13 @@ 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; } - pp = (char **)(void *)&(opts->pzProgPath); + pp = (char **)(void *)(intptr_t)&(opts->pzProgPath); *pp = tm_nm_buf; - pp = (char **)(void *)&(opts->pzProgName); + pp = (char **)(void *)(intptr_t)&(opts->pzProgName); *pp = tm_nm_buf; } @@ -653,7 +653,7 @@ emit_match_expr(char const * name, tOptDesc * cod, tOptions * opts) * They must not be the same. They cannot be, because it would * not compile correctly if they were. */ - while (toupper(od->pz_Name[match_ct]) == toupper(name[match_ct])) + while (toupper((unsigned char)od->pz_Name[match_ct]) == toupper((unsigned char)name[match_ct])) match_ct++; if (match_ct > min_match_ct) @@ -666,8 +666,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; @@ -901,11 +901,11 @@ genshelloptUsage(tOptions * opts, int exit_cd) */ { char * pz; - char ** pp = (char **)(void *)&(optionParseShellOptions->pzProgName); + char ** pp = (char **)(void *)(intptr_t)&(optionParseShellOptions->pzProgName); AGDUPSTR(pz, optionParseShellOptions->pzPROGNAME, "prog name"); *pp = pz; while (*pz != NUL) { - *pz = (char)tolower(*pz); + *pz = (char)tolower((unsigned char)*pz); pz++; } } diff --git a/sntp/libopts/nested.c b/sntp/libopts/nested.c index 0ec8f0880..96e45530f 100644 --- a/sntp/libopts/nested.c +++ b/sntp/libopts/nested.c @@ -645,7 +645,7 @@ unload_arg_list(tArgList * arg_list) char const ** pnew_val = arg_list->apzArgs; while (ct-- > 0) { - tOptionValue* new_val = (tOptionValue*)(void*)*(pnew_val++); + tOptionValue* new_val = (tOptionValue*)(void*)(intptr_t)*(pnew_val++); if (new_val->valType == OPARG_TYPE_HIERARCHY) unload_arg_list(new_val->v.nestVal); AGFREE(new_val); @@ -675,7 +675,7 @@ optionUnloadNested(tOptionValue const * opt_val) unload_arg_list(opt_val->v.nestVal); - AGFREE((void*)opt_val); + AGFREE((void*)(intptr_t)opt_val); } /** @@ -694,8 +694,8 @@ sort_list(tArgList * arg_list) */ for (ix = 0; ++ix < lm;) { int iy = ix-1; - tOptionValue * new_v = C(tOptionValue *, arg_list->apzArgs[ix]); - tOptionValue * old_v = C(tOptionValue *, arg_list->apzArgs[iy]); + tOptionValue * new_v = C(tOptionValue *, (intptr_t)arg_list->apzArgs[ix]); + tOptionValue * old_v = C(tOptionValue *, (intptr_t)arg_list->apzArgs[iy]); /* * For as long as the new entry precedes the "old" entry, @@ -704,7 +704,7 @@ sort_list(tArgList * arg_list) */ while (strcmp(old_v->pzName, new_v->pzName) > 0) { arg_list->apzArgs[iy+1] = (void*)old_v; - old_v = (tOptionValue*)(void*)(arg_list->apzArgs[--iy]); + old_v = (tOptionValue*)(void*)(intptr_t)(arg_list->apzArgs[--iy]); if (iy < 0) break; } @@ -837,7 +837,7 @@ optionNestedVal(tOptions * opts, tOptDesc * od) av = arg_list->apzArgs; while (--ct >= 0) { - void * p = (void *)*(av++); + void * p = (void *)(intptr_t)*(av++); optionUnloadNested((tOptionValue const *)p); } @@ -872,7 +872,7 @@ get_special_char(char const ** ppz, int * ct) base = 16; pz++; } - retch = (int)strtoul(pz, (char **)&pz, base); + retch = (int)strtoul(pz, (char **)(intptr_t)&pz, base); if (*pz != ';') return '&'; base = (int)(++pz - *ppz); diff --git a/sntp/libopts/numeric.c b/sntp/libopts/numeric.c index 9baba65e7..471cb936e 100644 --- a/sntp/libopts/numeric.c +++ b/sntp/libopts/numeric.c @@ -42,7 +42,7 @@ * Show information about a numeric option with range constraints. =*/ void -optionShowRange(tOptions * pOpts, tOptDesc * pOD, void * rng_table, int rng_ct) +optionShowRange(tOptions * pOpts, tOptDesc * pOD, const void * rng_table, int rng_ct) { const struct {long const rmin, rmax;} * rng = rng_table; diff --git a/sntp/libopts/parse-duration.c b/sntp/libopts/parse-duration.c index ff3fe4228..2536a06a0 100644 --- a/sntp/libopts/parse-duration.c +++ b/sntp/libopts/parse-duration.c @@ -60,14 +60,14 @@ typedef enum { static unsigned long str_const_to_ul (cch_t * str, cch_t ** ppz, int base) { - return strtoul (str, (char **)ppz, base); + return strtoul (str, (char **)(intptr_t)ppz, base); } /* 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); + return strtol (str, (char **)(intptr_t)ppz, base); } /* Returns BASE + VAL * SCALE, interpreting BASE = BAD_TIME diff --git a/sntp/libopts/pgusage.c b/sntp/libopts/pgusage.c index 80a89a713..a385b4d99 100644 --- a/sntp/libopts/pgusage.c +++ b/sntp/libopts/pgusage.c @@ -88,7 +88,7 @@ mk_pager_cmd(char const * fname) bfsz = strlen(fname) + strlen(pager) + PAGE_USAGE_FMT_LEN; res = AGALOC(bfsz, "more cmd"); snprintf(res, bfsz, PAGE_USAGE_FMT, pager, fname); - AGFREE((void*)fname); + AGFREE((void*)(intptr_t)fname); return res; } } diff --git a/sntp/libopts/reset.c b/sntp/libopts/reset.c index df81cd718..1e959a1e4 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, (char *)(intptr_t)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 19c4c5b84..dd51d6055 100644 --- a/sntp/libopts/save.c +++ b/sntp/libopts/save.c @@ -183,7 +183,7 @@ find_file_name(tOptions * opts, int * p_free_name) fprintf(stderr, zsave_warn, opts->pzProgName); fprintf(stderr, zNoStat, errno, strerror(errno), pzDir); if (free_dir_name) - AGFREE((void*)pzDir); + AGFREE(pzDir); return NULL; } @@ -223,7 +223,7 @@ find_file_name(tOptions * opts, int * p_free_name) sprintf(pzPath, "%s/%s", pzDir, opts->pzRcName); #endif if (free_dir_name) - AGFREE((void*)pzDir); + AGFREE(pzDir); pzDir = pzPath; free_dir_name = 1; } @@ -237,7 +237,7 @@ find_file_name(tOptions * opts, int * p_free_name) fprintf(stderr, zsave_warn, opts->pzProgName); fprintf(stderr, zNoStat, errno, strerror(errno), pzDir); - AGFREE((void*)pzDir); + AGFREE(pzDir); return NULL; } @@ -255,7 +255,7 @@ find_file_name(tOptions * opts, int * p_free_name) if (! S_ISREG(stBuf.st_mode)) { fprintf(stderr, zsave_warn, opts->pzProgName, pzDir); if (free_dir_name) - AGFREE((void*)pzDir); + AGFREE(pzDir); return NULL; } @@ -377,7 +377,7 @@ prt_value(FILE * fp, int depth, tOptDesc * pOD, tOptionValue const * ovp) /* * set membership strings get allocated */ - AGFREE((void*)pOD->optArg.argString); + AGFREE(pOD->optArg.argString); } } @@ -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 = (void **)(intptr_t)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 = (void **)(intptr_t)al->apzArgs; if (opt_ct <= 0) return; @@ -534,12 +534,12 @@ open_sv_file(tOptions * opts) fprintf(stderr, zsave_warn, opts->pzProgName); fprintf(stderr, zNoCreat, errno, strerror(errno), pzFName); if (free_name) - AGFREE((void*) pzFName ); + AGFREE(pzFName); return fp; } if (free_name) - AGFREE((void*)pzFName); + AGFREE(pzFName); } fputs("# ", fp); @@ -629,7 +629,7 @@ prt_enum_arg(FILE * fp, tOptDesc * od) * bit flag values back into a string suitable for printing. */ (*(od->pOptProc))(OPTPROC_RETURN_VALNAME, od); - prt_entry(fp, od, (void*)(od->optArg.argString)); + prt_entry(fp, od, (void*)(intptr_t)(od->optArg.argString)); od->optArg.argEnum = val; } diff --git a/sntp/libopts/tokenize.c b/sntp/libopts/tokenize.c index 34abf8360..a0db4cb80 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((char*)(intptr_t)pSrc, (char*)(intptr_t)&ch, 0x7F); if (ch == 0x7F) break; /* FALLTHROUGH */ diff --git a/sntp/libopts/usage.c b/sntp/libopts/usage.c index 206235d7a..bb33b35ac 100644 --- a/sntp/libopts/usage.c +++ b/sntp/libopts/usage.c @@ -435,7 +435,7 @@ print_one_paragraph(char const * text, bool plain, FILE * fp) else { char const * t = optionQuoteString(text, LINE_SPLICE); fprintf(fp, PUTS_FMT, t); - AGFREE((void *)t); + AGFREE(t); } } @@ -546,7 +546,7 @@ optionPrintParagraphs(char const * text, bool plain, FILE * fp) buf = scan; } } - AGFREE((void *)text); + AGFREE(text); } /*=export_func optionUsage diff --git a/sntp/main.c b/sntp/main.c index d60710868..c271c8c45 100644 --- a/sntp/main.c +++ b/sntp/main.c @@ -659,7 +659,7 @@ xmt( sockaddr_u * dst = &spkt->addr; struct timeval tv_xmt; struct pkt x_pkt; - int pkt_len; + size_t pkt_len; int sent; if (0 != gettimeofday(&tv_xmt, NULL)) { @@ -1248,7 +1248,7 @@ handle_pkt( if (synch_distance > 0.) { cnt = snprintf(disptxt, sizeof(disptxt), " +/- %f", synch_distance); - if (cnt >= sizeof(disptxt)) + if ((size_t)cnt >= sizeof(disptxt)) snprintf(disptxt, sizeof(disptxt), "ERROR %d >= %d", cnt, (int)sizeof(disptxt)); @@ -1392,7 +1392,7 @@ set_li_vn_mode ( leap = 3; } - if (version < 0 || version > 7) { + if ((unsigned char)version > 7) { msyslog(LOG_DEBUG, "set_li_vn_mode: version < 0 or > 7, using 4"); version = 4; } @@ -1545,7 +1545,7 @@ gettimeofday_cached( diff = sub_tval(systemt, latest); if (debug > 1) printf("system minus cached %+ld.%06ld\n", - (long)diff.tv_sec, diff.tv_usec); + (long)diff.tv_sec, (long)diff.tv_usec); if (0 != cgt_rc || labs((long)diff.tv_sec) < 3600) { /* * Either use_monotonic == 0, or this libevent @@ -1557,13 +1557,14 @@ gettimeofday_cached( diff = sub_tval(latest, mono); if (debug > 1) printf("cached minus monotonic %+ld.%06ld\n", - (long)diff.tv_sec, diff.tv_usec); + (long)diff.tv_sec, (long)diff.tv_usec); if (labs((long)diff.tv_sec) < 3600) { /* older libevent2 using monotonic */ offset = sub_tval(systemt, mono); TRACE(1, ("%s: Offsetting libevent CLOCK_MONOTONIC times by %+ld.%06ld\n", "gettimeofday_cached", - (long)offset.tv_sec, offset.tv_usec)); + (long)offset.tv_sec, + (long)offset.tv_usec)); } } offset_ready = TRUE; diff --git a/sntp/networking.c b/sntp/networking.c index 75c2f7140..bef7352d3 100644 --- a/sntp/networking.c +++ b/sntp/networking.c @@ -80,7 +80,7 @@ skip_efields( while ((tail - head) > 6) { nlen = ntohl(*head++) & 0xffff; nlen = (nlen + 3) >> 2; - if (nlen > (tail - head) || nlen < 4) + if (nlen > (u_int)(tail - head) || nlen < 4) return NULL; /* Blooper! Inconsistent! */ head += nlen; } @@ -129,8 +129,7 @@ process_pkt ( * extension field is present, so we subtract the length of the * field and go around again. */ - if (pkt_len < LEN_PKT_NOMAC || (pkt_len & 3) != 0) { -unusable: + if (pkt_len < (int)LEN_PKT_NOMAC || (pkt_len & 3) != 0) { msyslog(LOG_ERR, "%s: Incredible packet length: %d. Discarding.", func_name, pkt_len); @@ -139,8 +138,12 @@ unusable: /* Note: pkt_len must be a multiple of 4 at this point! */ packet_end = (u_int32*)((char*)rpkt + pkt_len); exten_end = skip_efields(rpkt->exten, packet_end); - if (NULL == exten_end) - goto unusable; + if (NULL == exten_end) { + msyslog(LOG_ERR, + "%s: Missing extension field. Discarding.", + func_name); + return PACKET_UNUSEABLE; + } /* get size of MAC in cells; can be zero */ exten_len = (u_int)(packet_end - exten_end); @@ -156,7 +159,10 @@ unusable: break; case 3: /* key ID + 3DES MAC -- unsupported! */ - goto unusable; + msyslog(LOG_ERR, + "%s: Key ID + 3DES MAC is unsupported. Discarding.", + func_name); + return PACKET_UNUSEABLE; case 5: /* key ID + MD5 MAC */ case 6: /* key ID + SHA MAC */ @@ -190,7 +196,10 @@ unusable: break; default: - goto unusable; + msyslog(LOG_ERR, + "%s: Unexpected extension length: %d. Discarding.", + func_name, exten_len); + return PACKET_UNUSEABLE; } switch (is_authentic) { diff --git a/sntp/sntp-opts.c b/sntp/sntp-opts.c index 3d9871028..a84b8067c 100644 --- a/sntp/sntp-opts.c +++ b/sntp/sntp-opts.c @@ -933,7 +933,7 @@ doOptSteplimit(tOptions* pOptions, tOptDesc* pOptDesc) option_usage_fp = stderr; emit_ranges: - optionShowRange(pOptions, pOptDesc, (void *)rng, 1); + optionShowRange(pOptions, pOptDesc, (void *)(intptr_t)rng, 1); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -969,7 +969,7 @@ doOptNtpversion(tOptions* pOptions, tOptDesc* pOptDesc) option_usage_fp = stderr; emit_ranges: - optionShowRange(pOptions, pOptDesc, (void *)rng, 1); + optionShowRange(pOptions, pOptDesc, (void *)(intptr_t)rng, 1); } /* extracted from optmain.tlib near line 1245 */ diff --git a/util/jitter.h b/util/jitter.h index 8c774b090..14314063b 100644 --- a/util/jitter.h +++ b/util/jitter.h @@ -137,9 +137,9 @@ typedef u_int32 u_fp; /* * Conversions between the two fixed point types */ -#define MFPTOFP(x_i, x_f) (((x_i) >= 0x00010000) ? 0x7fffffff : \ - (((x_i) <= -0x00010000) ? 0x80000000 : \ - (((x_i)<<16) | (((x_f)>>16)&0xffff)))) +#define MFPTOFP(x_i, x_f) (((int)(x_i) >= 0x00010000) ? 0x7fffffff : \ + (((int)(x_i) <= -0x00010000) ? 0x80000000 : \ + (u_int)(((x_i)<<16) | (((x_f)>>16)&0xffff)))) #define LFPTOFP(v) MFPTOFP((v)->l_i, (v)->l_f) #define UFPTOLFP(x, v) ((v)->l_ui = (u_fp)(x)>>16, (v)->l_uf = (x)<<16) diff --git a/util/ntp-keygen-opts.c b/util/ntp-keygen-opts.c index 7787dda68..6aeaf28b2 100644 --- a/util/ntp-keygen-opts.c +++ b/util/ntp-keygen-opts.c @@ -1047,7 +1047,7 @@ doOptImbits(tOptions* pOptions, tOptDesc* pOptDesc) option_usage_fp = stderr; emit_ranges: - optionShowRange(pOptions, pOptDesc, (void *)rng, 1); + optionShowRange(pOptions, pOptDesc, rng, 1); } #endif /* defined AUTOKEY */ @@ -1106,7 +1106,7 @@ doOptModulus(tOptions* pOptions, tOptDesc* pOptDesc) option_usage_fp = stderr; emit_ranges: - optionShowRange(pOptions, pOptDesc, (void *)rng, 1); + optionShowRange(pOptions, pOptDesc, rng, 1); } #endif /* defined AUTOKEY */ /* extracted from optmain.tlib near line 1245 */ diff --git a/util/ntp-keygen.c b/util/ntp-keygen.c index 6aed1a271..c16902161 100644 --- a/util/ntp-keygen.c +++ b/util/ntp-keygen.c @@ -108,6 +108,7 @@ #endif /* OPENSSL */ #include +#define _UC(str) ((char *)(intptr_t)(str)) /* * Cryptodefines */ @@ -131,19 +132,19 @@ * Prototypes */ FILE *fheader (const char *, const char *, const char *); -int gen_md5 (char *); +int gen_md5 (const char *); void followlink (char *, size_t); #ifdef AUTOKEY -EVP_PKEY *gen_rsa (char *); -EVP_PKEY *gen_dsa (char *); -EVP_PKEY *gen_iffkey (char *); -EVP_PKEY *gen_gqkey (char *); -EVP_PKEY *gen_mvkey (char *, EVP_PKEY **); +EVP_PKEY *gen_rsa (const char *); +EVP_PKEY *gen_dsa (const char *); +EVP_PKEY *gen_iffkey (const char *); +EVP_PKEY *gen_gqkey (const char *); +EVP_PKEY *gen_mvkey (const char *, EVP_PKEY **); void gen_mvserv (char *, EVP_PKEY **); -int x509 (EVP_PKEY *, const EVP_MD *, char *, char *, +int x509 (EVP_PKEY *, const EVP_MD *, char *, const char *, char *); void cb (int, int, void *); -EVP_PKEY *genkey (char *, char *); +EVP_PKEY *genkey (const char *, const char *); EVP_PKEY *readkey (char *, char *, u_int *, EVP_PKEY **); void writekey (char *, char *, u_int *, EVP_PKEY **); u_long asn2ntp (ASN1_TIME *); @@ -311,7 +312,7 @@ main( char pathbuf[MAXFILENAME + 1]; const char *scheme = NULL; /* digest/signature scheme */ const char *ciphername = NULL; /* to encrypt priv. key */ - char *exten = NULL; /* private extension */ + const char *exten = NULL; /* private extension */ char *grpkey = NULL; /* identity extension */ int nid; /* X509 digest/signature scheme */ FILE *fstr = NULL; /* file handle */ @@ -811,7 +812,7 @@ main( */ int gen_md5( - char *id /* file name id */ + const char *id /* file name id */ ) { u_char md5key[MD5SIZE + 1]; /* MD5 key */ @@ -958,7 +959,7 @@ readkey( */ EVP_PKEY * /* public/private key pair */ gen_rsa( - char *id /* file name id */ + const char *id /* file name id */ ) { EVP_PKEY *pkey; /* private key */ @@ -966,7 +967,7 @@ gen_rsa( FILE *str; fprintf(stderr, "Generating RSA keys (%d bits)...\n", modulus); - rsa = RSA_generate_key(modulus, 65537, cb, "RSA"); + rsa = RSA_generate_key(modulus, 65537, cb, _UC("RSA")); fprintf(stderr, "\n"); if (rsa == NULL) { fprintf(stderr, "RSA generate keys fails\n%s\n", @@ -1011,7 +1012,7 @@ gen_rsa( */ EVP_PKEY * /* public/private key pair */ gen_dsa( - char *id /* file name id */ + const char *id /* file name id */ ) { EVP_PKEY *pkey; /* private key */ @@ -1026,7 +1027,7 @@ gen_dsa( "Generating DSA parameters (%d bits)...\n", modulus); RAND_bytes(seed, sizeof(seed)); dsa = DSA_generate_parameters(modulus, seed, sizeof(seed), NULL, - NULL, cb, "DSA"); + NULL, cb, _UC("DSA")); fprintf(stderr, "\n"); if (dsa == NULL) { fprintf(stderr, "DSA generate parameters fails\n%s\n", @@ -1113,7 +1114,7 @@ gen_dsa( */ EVP_PKEY * /* DSA cuckoo nest */ gen_iffkey( - char *id /* file name id */ + const char *id /* file name id */ ) { EVP_PKEY *pkey; /* private key */ @@ -1131,7 +1132,7 @@ gen_iffkey( modulus2); RAND_bytes(seed, sizeof(seed)); dsa = DSA_generate_parameters(modulus2, seed, sizeof(seed), NULL, - NULL, cb, "IFF"); + NULL, cb, _UC("IFF")); fprintf(stderr, "\n"); if (dsa == NULL) { fprintf(stderr, "DSA generate parameters fails\n%s\n", @@ -1291,7 +1292,7 @@ gen_iffkey( */ EVP_PKEY * /* RSA cuckoo nest */ gen_gqkey( - char *id /* file name id */ + const char *id /* file name id */ ) { EVP_PKEY *pkey; /* private key */ @@ -1307,7 +1308,7 @@ gen_gqkey( fprintf(stderr, "Generating GQ parameters (%d bits)...\n", modulus2); - rsa = RSA_generate_key(modulus2, 65537, cb, "GQ"); + rsa = RSA_generate_key(modulus2, 65537, cb, _UC("GQ")); fprintf(stderr, "\n"); if (rsa == NULL) { fprintf(stderr, "RSA generate keys fails\n%s\n", @@ -1500,7 +1501,7 @@ gen_gqkey( */ EVP_PKEY * /* DSA cuckoo nest */ gen_mvkey( - char *id, /* file name id */ + const char *id, /* file name id */ EVP_PKEY **evpars /* parameter list pointer */ ) { @@ -1925,7 +1926,7 @@ x509 ( EVP_PKEY *pkey, /* signing key */ const EVP_MD *md, /* signature/digest scheme */ char *gqpub, /* identity extension (hex string) */ - char *exten, /* private cert extension */ + const char *exten, /* private cert extension */ char *name /* subject/issuer name */ ) { @@ -1979,7 +1980,7 @@ x509 ( fprintf(stderr, "%s: %s\n", LN_basic_constraints, BASIC_CONSTRAINTS); ex = X509V3_EXT_conf_nid(NULL, NULL, NID_basic_constraints, - BASIC_CONSTRAINTS); + _UC(BASIC_CONSTRAINTS)); if (!X509_add_ext(cert, ex, -1)) { fprintf(stderr, "Add extension field fails\n%s\n", ERR_error_string(ERR_get_error(), NULL)); @@ -1992,7 +1993,7 @@ x509 ( * be used for. */ fprintf(stderr, "%s: %s\n", LN_key_usage, KEY_USAGE); - ex = X509V3_EXT_conf_nid(NULL, NULL, NID_key_usage, KEY_USAGE); + ex = X509V3_EXT_conf_nid(NULL, NULL, NID_key_usage, _UC(KEY_USAGE)); if (!X509_add_ext(cert, ex, -1)) { fprintf(stderr, "Add extension field fails\n%s\n", ERR_error_string(ERR_get_error(), NULL)); @@ -2027,7 +2028,7 @@ x509 ( if (exten != NULL) { fprintf(stderr, "%s: %s\n", LN_ext_key_usage, exten); ex = X509V3_EXT_conf_nid(NULL, NULL, - NID_ext_key_usage, exten); + NID_ext_key_usage, _UC(exten)); if (!X509_add_ext(cert, ex, -1)) { fprintf(stderr, "Add extension field fails\n%s\n", @@ -2138,8 +2139,8 @@ cb ( */ EVP_PKEY * /* public/private key pair */ genkey( - char *type, /* key type (RSA or DSA) */ - char *id /* file name id */ + const char *type, /* key type (RSA or DSA) */ + const char *id /* file name id */ ) { if (type == NULL) diff --git a/util/ntptime.c b/util/ntptime.c index dd5605ca7..5a6c1d164 100644 --- a/util/ntptime.c +++ b/util/ntptime.c @@ -98,15 +98,16 @@ main( volatile unsigned ts_mask = TS_MASK; /* defaults to 20 bits (us) */ volatile unsigned ts_roundbit = TS_ROUNDBIT; /* defaults to 20 bits (us) */ volatile int fdigits = 6; /* fractional digits for us */ - int c; + size_t c; + int ch; int errflg = 0; int cost = 0; volatile int rawtime = 0; ZERO(ntx); progname = argv[0]; - while ((c = ntp_getopt(argc, argv, optargs)) != EOF) { - switch (c) { + while ((ch = ntp_getopt(argc, argv, optargs)) != EOF) { + switch (ch) { #ifdef MOD_MICRO case 'M': ntx.modes |= MOD_MICRO; @@ -467,7 +468,7 @@ timex_state( { static char buf[32]; - if (s >= 0 && s < COUNTOF(timex_states)) + if ((size_t)s < COUNTOF(timex_states)) return timex_states[s]; snprintf(buf, sizeof(buf), "TIME-#%d", s); return buf;