]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
cmdmon: avoid unsigned shorts
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 17 Jun 2020 08:28:14 +0000 (10:28 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Wed, 17 Jun 2020 13:24:55 +0000 (15:24 +0200)
Change unsigned shorts to uint16_t or longer types to avoid any
assumptions about length of the short type.

client.c
cmdmon.c
cmdparse.c
cmdparse.h
reports.h

index f6652ba659ed1b98dce633499fe49ca84d939b9b..8001cd5f8f486b8d46f0d9a16423fdcdac1a8967 100644 (file)
--- 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);
index bdaf711340e4337b7ead2e37708379dc06d31134..ebc7fe09fdd2623fa1519f9546ce16d07d43882b 100644 (file)
--- 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);
index 0124586ea9ca11b922ff07112d1848c4b7bb488c..33ee834cf65fdf8f2757ee4c6a7b828d2a69de10 100644 (file)
@@ -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)
index 694d12dd0c9c1011b9feac79e5ab470646d4e73e..199d9722c5d99c78a41f0d11d7e327143183753f 100644 (file)
@@ -32,7 +32,7 @@
 
 typedef struct {
   char *name;
-  unsigned short port;
+  int port;
   SourceParameters params;
 } CPS_NTP_Source;
 
index a1244db6892fccac46872a5d25d6bcd92437e155..b4a6dfa7d7eb2c6befd402bafe8e8d6409c274c1 100644 (file)
--- 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;