]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
fix -Wshadow warnings
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 19 Nov 2025 15:05:38 +0000 (16:05 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 20 Nov 2025 09:22:45 +0000 (10:22 +0100)
Rename variables to avoid conflicts in naming of local and global
variables.

clientlog.c
conf.c
ntp_signd.c
rtc_linux.c
sys_linux.c
tempcomp.c
test/unit/keys.c
test/unit/nts_ke_session.c

index b52a5730d85ee563078d3aedff3f7fc095dcc347..e18f8fced6ef6f9d6d4aefe19ac1a9733795b1f2 100644 (file)
@@ -328,30 +328,28 @@ expand_hashtable(void)
 /* ================================================== */
 
 static void
-set_bucket_params(int interval, int burst, uint16_t *max_tokens,
-                  uint16_t *tokens_per_packet, int *token_shift)
+set_bucket_params(int interval, int burst, uint16_t *mtokens, uint16_t *tphit, int *tshift)
 {
   interval = CLAMP(MIN_LIMIT_INTERVAL, interval, MAX_LIMIT_INTERVAL);
   burst = CLAMP(MIN_LIMIT_BURST, burst, MAX_LIMIT_BURST);
 
   if (interval >= -TS_FRAC) {
     /* Find the smallest shift with which the maximum number fits in 16 bits */
-    for (*token_shift = 0; *token_shift < interval + TS_FRAC; (*token_shift)++) {
-      if (burst << (TS_FRAC + interval - *token_shift) < 1U << 16)
+    for (*tshift = 0; *tshift < interval + TS_FRAC; (*tshift)++) {
+      if (burst << (TS_FRAC + interval - *tshift) < 1U << 16)
         break;
     }
   } else {
     /* Coarse rate limiting */
-    *token_shift = interval + TS_FRAC;
-    *tokens_per_packet = 1;
-    burst = MAX(1U << -*token_shift, burst);
+    *tshift = interval + TS_FRAC;
+    *tphit = 1;
+    burst = MAX(1U << -*tshift, burst);
   }
 
-  *tokens_per_packet = 1U << (TS_FRAC + interval - *token_shift);
-  *max_tokens = *tokens_per_packet * burst;
+  *tphit = 1U << (TS_FRAC + interval - *tshift);
+  *mtokens = *tphit * burst;
 
-  DEBUG_LOG("Tokens max %d packet %d shift %d",
-            *max_tokens, *tokens_per_packet, *token_shift);
+  DEBUG_LOG("Tokens max %d packet %d shift %d", *mtokens, *tphit, *tshift);
 }
 
 /* ================================================== */
diff --git a/conf.c b/conf.c
index d7a22f690120dab5df29f162c98818ecc179608c..b19bd204245f87c7f53b9ee6095e17b1092b142e 100644 (file)
--- a/conf.c
+++ b/conf.c
@@ -968,7 +968,7 @@ parse_ratelimit(char *line, int *enabled, int *interval, int *burst, int *leak,
 static void
 parse_refclock(char *line)
 {
-  int n, poll, dpoll, filter_length, pps_rate, min_samples, max_samples, sel_options;
+  int n, poll, dpoll, filter_length, pps_rate, min_samples_, max_samples_, sel_options;
   int local, max_lock_age, max_unreach, pps_forced, sel_option, stratum, tai;
   uint32_t ref_id, lock_ref_id;
   double offset, delay, precision, max_dispersion, pulse_width;
@@ -981,8 +981,8 @@ parse_refclock(char *line)
   local = 0;
   pps_forced = 0;
   pps_rate = 0;
-  min_samples = SRC_DEFAULT_MINSAMPLES;
-  max_samples = SRC_DEFAULT_MAXSAMPLES;
+  min_samples_ = SRC_DEFAULT_MINSAMPLES;
+  max_samples_ = SRC_DEFAULT_MAXSAMPLES;
   max_unreach = SRC_DEFAULT_MAXUNREACH;
   sel_options = 0;
   offset = 0.0;
@@ -1040,13 +1040,13 @@ parse_refclock(char *line)
       if (!SSCANF_IN_RANGE(line, "%d%n", &pps_rate, &n, 1, INT_MAX))
         break;
     } else if (!strcasecmp(cmd, "minsamples")) {
-      if (!SSCANF_IN_RANGE(line, "%d%n", &min_samples, &n, 0, INT_MAX))
+      if (!SSCANF_IN_RANGE(line, "%d%n", &min_samples_, &n, 0, INT_MAX))
         break;
     } else if (!strcasecmp(cmd, "maxlockage")) {
       if (!SSCANF_IN_RANGE(line, "%d%n", &max_lock_age, &n, 0, INT_MAX))
         break;
     } else if (!strcasecmp(cmd, "maxsamples")) {
-      if (!SSCANF_IN_RANGE(line, "%d%n", &max_samples, &n, 0, INT_MAX))
+      if (!SSCANF_IN_RANGE(line, "%d%n", &max_samples_, &n, 0, INT_MAX))
         break;
     } else if (!strcasecmp(cmd, "maxunreach")) {
       if (!SSCANF_IN_RANGE(line, "%d%n", &max_unreach, &n, 0, INT_MAX))
@@ -1098,8 +1098,8 @@ parse_refclock(char *line)
   refclock->local = local;
   refclock->pps_forced = pps_forced;
   refclock->pps_rate = pps_rate;
-  refclock->min_samples = min_samples;
-  refclock->max_samples = max_samples;
+  refclock->min_samples = min_samples_;
+  refclock->max_samples = max_samples_;
   refclock->max_unreach = max_unreach;
   refclock->sel_options = sel_options;
   refclock->stratum = stratum;
@@ -2448,16 +2448,16 @@ CNF_GetLogChange(void)
 /* ================================================== */
 
 void
-CNF_GetMailOnChange(int *enabled, double *threshold, char **user)
+CNF_GetMailOnChange(int *enabled, double *threshold, char **user_)
 {
   if (mail_user_on_change) {
     *enabled = 1;
     *threshold = mail_change_threshold;
-    *user = mail_user_on_change;
+    *user_ = mail_user_on_change;
   } else {
     *enabled = 0;
     *threshold = 0.0;
-    *user = NULL;
+    *user_ = NULL;
   }
 }  
 
index e52c8f51c040ca4867e5e4129bbe11033cf8f95d..ce0ffe5d67efd6c9297a1d8f0f801730ab84a6c5 100644 (file)
@@ -104,7 +104,7 @@ static int logged_connection_error;
 
 /* ================================================== */
 
-static void read_write_socket(int sock_fd, int event, void *anything);
+static void read_write_socket(int fd, int event, void *anything);
 
 /* ================================================== */
 
@@ -193,7 +193,7 @@ process_response(SignInstance *inst)
 /* ================================================== */
 
 static void
-read_write_socket(int sock_fd, int event, void *anything)
+read_write_socket(int fd, int event, void *anything)
 {
   SignInstance *inst;
   uint32_t response_length;
@@ -208,7 +208,7 @@ read_write_socket(int sock_fd, int event, void *anything)
     if (!inst->sent)
       SCH_GetLastEventTime(NULL, NULL, &inst->request_ts);
 
-    s = SCK_Send(sock_fd, (char *)&inst->request + inst->sent,
+    s = SCK_Send(fd, (char *)&inst->request + inst->sent,
                  inst->request_length - inst->sent, 0);
 
     if (s < 0) {
@@ -223,7 +223,7 @@ read_write_socket(int sock_fd, int event, void *anything)
       return;
 
     /* Disable output and wait for a response */
-    SCH_SetFileHandlerEvent(sock_fd, SCH_FILE_OUTPUT, 0);
+    SCH_SetFileHandlerEvent(fd, SCH_FILE_OUTPUT, 0);
   }
 
   if (event == SCH_FILE_INPUT) {
@@ -234,7 +234,7 @@ read_write_socket(int sock_fd, int event, void *anything)
     }
 
     assert(inst->received < sizeof (inst->response));
-    s = SCK_Receive(sock_fd, (char *)&inst->response + inst->received,
+    s = SCK_Receive(fd, (char *)&inst->response + inst->received,
                     sizeof (inst->response) - inst->received, 0);
 
     if (s <= 0) {
@@ -265,7 +265,7 @@ read_write_socket(int sock_fd, int event, void *anything)
     /* Move the head and enable output for the next packet */
     queue_head = NEXT_QUEUE_INDEX(queue_head);
     if (!IS_QUEUE_EMPTY())
-      SCH_SetFileHandlerEvent(sock_fd, SCH_FILE_OUTPUT, 1);
+      SCH_SetFileHandlerEvent(fd, SCH_FILE_OUTPUT, 1);
   }
 }
 
index 0d443223cb4b513e66095756064a1bebc880926d..08ba5b526ea6e0eb6048bf11577d4c6ab841bb47 100644 (file)
@@ -51,7 +51,7 @@
 
 static void measurement_timeout(void *any);
 
-static void read_from_device(int fd_, int event, void *any);
+static void read_from_device(int fd, int event, void *any);
 
 /* ================================================== */
 
@@ -65,7 +65,7 @@ static OperatingMode operating_mode = OM_NORMAL;
 
 /* ================================================== */
 
-static int fd;
+static int rtc_fd;
 
 #define LOWEST_MEASUREMENT_PERIOD 15
 #define HIGHEST_MEASUREMENT_PERIOD 480
@@ -522,21 +522,21 @@ int
 RTC_Linux_Initialise(void)
 {
   /* Try to open the device */
-  fd = open(CNF_GetRtcDevice(), O_RDWR);
-  if (fd < 0) {
+  rtc_fd = open(CNF_GetRtcDevice(), O_RDWR);
+  if (rtc_fd < 0) {
     LOG(LOGS_ERR, "Could not open RTC device %s : %s",
         CNF_GetRtcDevice(), strerror(errno));
     return 0;
   }
 
   /* Make sure the RTC supports interrupts */
-  if (!RTC_Linux_SwitchInterrupt(fd, 1) || !RTC_Linux_SwitchInterrupt(fd, 0)) {
-    close(fd);
+  if (!RTC_Linux_SwitchInterrupt(rtc_fd, 1) || !RTC_Linux_SwitchInterrupt(rtc_fd, 0)) {
+    close(rtc_fd);
     return 0;
   }
 
   /* Close on exec */
-  UTI_FdSetCloexec(fd);
+  UTI_FdSetCloexec(rtc_fd);
 
   rtc_sec = MallocArray(time_t, MAX_SAMPLES);
   system_times = MallocArray(struct timespec, MAX_SAMPLES);
@@ -557,7 +557,7 @@ RTC_Linux_Initialise(void)
   operating_mode = OM_NORMAL;
 
   /* Register file handler */
-  SCH_AddFileHandler(fd, SCH_FILE_INPUT, read_from_device, NULL);
+  SCH_AddFileHandler(rtc_fd, SCH_FILE_INPUT, read_from_device, NULL);
 
   /* Register slew handler */
   LCL_AddParameterChangeHandler(slew_samples, NULL);
@@ -577,10 +577,10 @@ RTC_Linux_Finalise(void)
   timeout_id = 0;
 
   /* Remove input file handler */
-  if (fd >= 0) {
-    SCH_RemoveFileHandler(fd);
-    RTC_Linux_SwitchInterrupt(fd, 0);
-    close(fd);
+  if (rtc_fd >= 0) {
+    SCH_RemoveFileHandler(rtc_fd);
+    RTC_Linux_SwitchInterrupt(rtc_fd, 0);
+    close(rtc_fd);
 
     /* Save the RTC data */
     (void) RTC_Linux_WriteParameters();
@@ -600,7 +600,7 @@ static void
 measurement_timeout(void *any)
 {
   timeout_id = 0;
-  RTC_Linux_SwitchInterrupt(fd, 1);
+  RTC_Linux_SwitchInterrupt(rtc_fd, 1);
 }
 
 /* ================================================== */
@@ -613,7 +613,7 @@ set_rtc(time_t new_rtc_time)
 
   rtc_from_t(&new_rtc_time, &rtc_raw, rtc_on_utc);
 
-  status = ioctl(fd, RTC_SET_TIME, &rtc_raw);
+  status = ioctl(rtc_fd, RTC_SET_TIME, &rtc_raw);
   if (status < 0) {
     LOG(LOGS_ERR, "Could not set RTC time");
   }
@@ -810,25 +810,26 @@ RTC_Linux_ReadTimeAfterInterrupt(int fd, int utc,
 }
 
 static void
-read_from_device(int fd_, int event, void *any)
+read_from_device(int fd, int event, void *any)
 {
   struct timespec sys_time;
   int status, error = 0;
   time_t rtc_t;
 
-  status = RTC_Linux_CheckInterrupt(fd);
+  status = RTC_Linux_CheckInterrupt(rtc_fd);
   if (status < 0) {
-    SCH_RemoveFileHandler(fd);
-    RTC_Linux_SwitchInterrupt(fd, 0); /* Likely to raise error too, but just to be sure... */
-    close(fd);
-    fd = -1;
+    SCH_RemoveFileHandler(rtc_fd);
+    /* Likely to raise error too, but just to be sure... */
+    RTC_Linux_SwitchInterrupt(rtc_fd, 0);
+    close(rtc_fd);
+    rtc_fd = -1;
     return;
   } else if (status == 0) {
     /* Wait for the next interrupt, this one may be bogus */
     return;
   }
 
-  rtc_t = RTC_Linux_ReadTimeAfterInterrupt(fd, rtc_on_utc, &sys_time, NULL);
+  rtc_t = RTC_Linux_ReadTimeAfterInterrupt(rtc_fd, rtc_on_utc, &sys_time, NULL);
   if (rtc_t == (time_t)-1) {
     error = 1;
     goto turn_off_interrupt;
@@ -857,7 +858,7 @@ turn_off_interrupt:
         operating_mode = OM_NORMAL;
         (after_init_hook)(after_init_hook_arg);
 
-        RTC_Linux_SwitchInterrupt(fd, 0);
+        RTC_Linux_SwitchInterrupt(rtc_fd, 0);
     
         timeout_id = SCH_AddTimeoutByDelay((double) measurement_period, measurement_timeout, NULL);
       }
@@ -869,7 +870,7 @@ turn_off_interrupt:
         DEBUG_LOG("Could not complete after trim relock due to errors");
         operating_mode = OM_NORMAL;
 
-        RTC_Linux_SwitchInterrupt(fd, 0);
+        RTC_Linux_SwitchInterrupt(rtc_fd, 0);
     
         timeout_id = SCH_AddTimeoutByDelay((double) measurement_period, measurement_timeout, NULL);
       }
@@ -877,7 +878,7 @@ turn_off_interrupt:
       break;
 
     case OM_NORMAL:
-      RTC_Linux_SwitchInterrupt(fd, 0);
+      RTC_Linux_SwitchInterrupt(rtc_fd, 0);
     
       timeout_id = SCH_AddTimeoutByDelay((double) measurement_period, measurement_timeout, NULL);
 
@@ -899,7 +900,7 @@ RTC_Linux_TimeInit(void (*after_hook)(void *), void *anything)
 
   operating_mode = OM_INITIAL;
   timeout_id = 0;
-  RTC_Linux_SwitchInterrupt(fd, 1);
+  RTC_Linux_SwitchInterrupt(rtc_fd, 1);
 }
 
 /* ================================================== */
@@ -917,7 +918,7 @@ RTC_Linux_WriteParameters(void)
 {
   int retval;
 
-  if (fd < 0) {
+  if (rtc_fd < 0) {
     return RTC_ST_NODRV;
   }
   
@@ -1086,7 +1087,7 @@ RTC_Linux_Trim(void)
     /* And start rapid sampling, interrupts on now */
     SCH_RemoveTimeout(timeout_id);
     timeout_id = 0;
-    RTC_Linux_SwitchInterrupt(fd, 1);
+    RTC_Linux_SwitchInterrupt(rtc_fd, 1);
   }
 
   return 1;
index 89eec9504ba11fafd0dcbd1ffa9258dce46c0388..58b20a6390d93764f104d36899ccffd1ef21ed1f 100644 (file)
@@ -94,7 +94,7 @@ static int current_delta_tick;
 static int max_tick_bias;
 
 /* The kernel USER_HZ constant */
-static int hz;
+static int sys_hz;
 static double dhz; /* And dbl prec version of same for arithmetic */
 
 /* The assumed rate at which the effective frequency and tick values are
@@ -149,8 +149,8 @@ set_frequency(double freq_ppm)
      USER_HZ <= 250, the maximum frequency adjustment of 500 ppm overlaps at
      least two ticks and we can stick to the current tick if it's next to the
      required tick. */
-  if (hz <= 250 && (required_delta_tick + 1 == current_delta_tick ||
-                    required_delta_tick - 1 == current_delta_tick)) {
+  if (sys_hz <= 250 && (required_delta_tick + 1 == current_delta_tick ||
+                        required_delta_tick - 1 == current_delta_tick)) {
     required_delta_tick = current_delta_tick;
   }
 
@@ -278,13 +278,14 @@ get_kernel_version(int *major, int *minor, int *patch)
 static void
 get_version_specific_details(void)
 {
-  int major, minor, patch;
+  int hz, major, minor, patch;
   
   hz = get_hz();
 
   if (!hz)
     hz = guess_hz();
 
+  sys_hz = hz;
   dhz = (double) hz;
   nominal_tick = (1000000L + (hz/2))/hz; /* Mirror declaration in kernel */
   max_tick_bias = nominal_tick / 10;
index 4c363676fd606af462eccb76307364a6b52463a0..1354184783c7ad225ae858fe76b8bedfd785db3b 100644 (file)
@@ -115,20 +115,20 @@ read_timeout(void *arg)
 }
 
 static void
-read_points(const char *filename)
+read_points(const char *path)
 {
   FILE *f;
   char line[256];
   struct Point *p;
 
-  f = UTI_OpenFile(NULL, filename, NULL, 'R', 0);
+  f = UTI_OpenFile(NULL, path, NULL, 'R', 0);
 
   points = ARR_CreateInstance(sizeof (struct Point));
 
   while (fgets(line, sizeof (line), f)) {
     p = (struct Point *)ARR_GetNewElement(points);
     if (sscanf(line, "%lf %lf", &p->temp, &p->comp) != 2) {
-      LOG_FATAL("Could not read tempcomp point from %s", filename);
+      LOG_FATAL("Could not read tempcomp point from %s", path);
       break;
     }
   }
@@ -136,7 +136,7 @@ read_points(const char *filename)
   fclose(f);
 
   if (ARR_GetSize(points) < 2)
-    LOG_FATAL("Not enough points in %s", filename);
+    LOG_FATAL("Not enough points in %s", path);
 }
 
 void
index b6ee12af4642aa2889eebb74d1234d39e4878b33..014a0fae5f9cc9fc5d1fc9612b064a1f2f4afcdf 100644 (file)
@@ -84,7 +84,7 @@ uint32_t write_random_key(FILE *f)
 }
 
 static void
-generate_key_file(const char *name, uint32_t *keys)
+generate_key_file(const char *name, uint32_t *key_ids)
 {
   FILE *f;
   int i;
@@ -92,7 +92,7 @@ generate_key_file(const char *name, uint32_t *keys)
   f = fopen(name, "w");
   TEST_CHECK(f);
   for (i = 0; i < KEYS; i++)
-    keys[i] = write_random_key(f);
+    key_ids[i] = write_random_key(f);
   fclose(f);
 }
 
@@ -100,7 +100,7 @@ void
 test_unit(void)
 {
   int i, j, data_len, auth_len, type, bits, s, timing_fails, timing_iters;
-  uint32_t keys[KEYS], key;
+  uint32_t key_ids[KEYS], key;
   unsigned char data[100], auth[MAX_HASH_LENGTH], auth2[MAX_HASH_LENGTH];
   struct timespec ts1, ts2;
   double diff1, diff2;
@@ -113,41 +113,41 @@ test_unit(void)
     CNF_ParseLine(NULL, i + 1, conf[i]);
   LCL_Initialise();
 
-  generate_key_file(KEYFILE, keys);
+  generate_key_file(KEYFILE, key_ids);
   KEY_Initialise();
 
   for (i = 0; i < 100; i++) {
     DEBUG_LOG("iteration %d", i);
 
     if (i) {
-      generate_key_file(KEYFILE, keys);
+      generate_key_file(KEYFILE, key_ids);
       KEY_Reload();
     }
 
     UTI_GetRandomBytes(data, sizeof (data));
 
     for (j = 0; j < KEYS; j++) {
-      TEST_CHECK(KEY_KeyKnown(keys[j]));
-      TEST_CHECK(KEY_GetAuthLength(keys[j]) >= 16);
+      TEST_CHECK(KEY_KeyKnown(key_ids[j]));
+      TEST_CHECK(KEY_GetAuthLength(key_ids[j]) >= 16);
 
       data_len = random() % (sizeof (data) + 1);
-      auth_len = KEY_GenerateAuth(keys[j], data, data_len, auth, sizeof (auth));
+      auth_len = KEY_GenerateAuth(key_ids[j], data, data_len, auth, sizeof (auth));
       TEST_CHECK(auth_len >= 16);
 
-      TEST_CHECK(KEY_CheckAuth(keys[j], data, data_len, auth, auth_len, auth_len));
+      TEST_CHECK(KEY_CheckAuth(key_ids[j], data, data_len, auth, auth_len, auth_len));
 
-      if (j > 0 && keys[j - 1] != keys[j])
-        TEST_CHECK(!KEY_CheckAuth(keys[j - 1], data, data_len, auth, auth_len, auth_len));
+      if (j > 0 && key_ids[j - 1] != key_ids[j])
+        TEST_CHECK(!KEY_CheckAuth(key_ids[j - 1], data, data_len, auth, auth_len, auth_len));
 
       auth_len = random() % auth_len + 1;
       if (auth_len < MAX_HASH_LENGTH)
         auth[auth_len]++;
-      TEST_CHECK(KEY_CheckAuth(keys[j], data, data_len, auth, auth_len, auth_len));
+      TEST_CHECK(KEY_CheckAuth(key_ids[j], data, data_len, auth, auth_len, auth_len));
 
       auth[auth_len - 1]++;
-      TEST_CHECK(!KEY_CheckAuth(keys[j], data, data_len, auth, auth_len, auth_len));
+      TEST_CHECK(!KEY_CheckAuth(key_ids[j], data, data_len, auth, auth_len, auth_len));
 
-      TEST_CHECK(KEY_GetKeyInfo(keys[j], &type, &bits));
+      TEST_CHECK(KEY_GetKeyInfo(key_ids[j], &type, &bits));
       TEST_CHECK(type > 0 && bits > 0);
     }
 
index 7e6d957d57dc99a33784306bb0857217851244b3..b92825d7a96d54f878890760f0e99de476e6064e 100644 (file)
@@ -134,13 +134,13 @@ verify_message(NKSN_Instance inst)
 static int
 handle_request(void *arg)
 {
-  NKSN_Instance server = arg;
+  NKSN_Instance inst = arg;
 
-  verify_message(server);
+  verify_message(inst);
 
   request_received = 1;
 
-  send_message(server);
+  send_message(inst);
 
   return 1;
 }
@@ -148,11 +148,11 @@ handle_request(void *arg)
 static int
 handle_response(void *arg)
 {
-  NKSN_Instance client = arg;
+  NKSN_Instance inst = arg;
 
   response_received = 1;
 
-  verify_message(client);
+  verify_message(inst);
 
   return 1;
 }