From f9e2a5852da62d33a72e1915d0a8a439ff6a31fd Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 17 Jun 2020 10:28:14 +0200 Subject: [PATCH] cmdmon: avoid unsigned shorts Change unsigned shorts to uint16_t or longer types to avoid any assumptions about length of the short type. --- client.c | 2 +- cmdmon.c | 4 ++-- cmdparse.c | 2 +- cmdparse.h | 2 +- reports.h | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/client.c b/client.c index f6652ba..8001cd5 100644 --- a/client.c +++ b/client.c @@ -1120,7 +1120,7 @@ process_cmd_add_source(CMD_Request *msg, char *line) assert(0); strncpy((char *)msg->data.ntp_source.name, data.name, sizeof (msg->data.ntp_source.name)); - msg->data.ntp_source.port = htonl((unsigned long) data.port); + msg->data.ntp_source.port = htonl(data.port); msg->data.ntp_source.minpoll = htonl(data.params.minpoll); msg->data.ntp_source.maxpoll = htonl(data.params.maxpoll); msg->data.ntp_source.presend_minpoll = htonl(data.params.presend_minpoll); diff --git a/cmdmon.c b/cmdmon.c index bdaf711..ebc7fe0 100644 --- a/cmdmon.c +++ b/cmdmon.c @@ -716,7 +716,7 @@ handle_add_source(CMD_Request *rx_message, CMD_Reply *tx_message) return; } - port = (unsigned short)(ntohl(rx_message->data.ntp_source.port)); + port = ntohl(rx_message->data.ntp_source.port); params.minpoll = ntohl(rx_message->data.ntp_source.minpoll); params.maxpoll = ntohl(rx_message->data.ntp_source.maxpoll); params.presend_minpoll = ntohl(rx_message->data.ntp_source.presend_minpoll); @@ -1341,7 +1341,7 @@ read_from_cmd_socket(int sock_fd, int event, void *anything) IPAddr loopback_addr, remote_ip; int read_length, expected_length; int localhost, allowed, log_index; - unsigned short rx_command; + uint16_t rx_command; struct timespec now, cooked_now; sck_message = SCK_ReceiveMessage(sock_fd, 0); diff --git a/cmdparse.c b/cmdparse.c index 0124586..33ee834 100644 --- a/cmdparse.c +++ b/cmdparse.c @@ -151,7 +151,7 @@ CPS_ParseNTPSourceAdd(char *line, CPS_NTP_Source *src) if (sscanf(line, "%lf%n", &src->params.offset, &n) != 1) return 0; } else if (!strcasecmp(cmd, "port")) { - if (sscanf(line, "%hu%n", &src->port, &n) != 1) + if (sscanf(line, "%d%n", &src->port, &n) != 1) return 0; } else if (!strcasecmp(cmd, "polltarget")) { if (sscanf(line, "%d%n", &src->params.poll_target, &n) != 1) diff --git a/cmdparse.h b/cmdparse.h index 694d12d..199d972 100644 --- a/cmdparse.h +++ b/cmdparse.h @@ -32,7 +32,7 @@ typedef struct { char *name; - unsigned short port; + int port; SourceParameters params; } CPS_NTP_Source; diff --git a/reports.h b/reports.h index a1244db..b4a6dfa 100644 --- a/reports.h +++ b/reports.h @@ -77,8 +77,8 @@ typedef struct { typedef struct { struct timespec ref_time; - unsigned short n_samples; - unsigned short n_runs; + unsigned long n_samples; + unsigned long n_runs; unsigned long span_seconds; double rtc_seconds_fast; double rtc_gain_rate_ppm;