This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit fe336a9b22e13f6015016772b6bbf5caca027e9d Author: wangzitong7 <[email protected]> AuthorDate: Thu Dec 18 10:12:31 2025 +0800 netutils/ptpd: widen products to int64_t before they overflow. interval_s * MSEC_PER_SEC and drift_ppb * CONFIG_CLOCK_ADJTIME_PERIOD_MS were computed in long, which is 32 bits on most targets; a large drift or delay-request interval overflowed before the result was widened. Cast one operand to int64_t first. Signed-off-by: wangzitong7 <[email protected]> Assisted-by: Kiro:claude-opus-4 --- netutils/ptpd/ptpd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/netutils/ptpd/ptpd.c b/netutils/ptpd/ptpd.c index 2740cafe0..3e4e47dbd 100644 --- a/netutils/ptpd/ptpd.c +++ b/netutils/ptpd/ptpd.c @@ -1446,7 +1446,7 @@ static int ptp_periodic_send(FAR struct ptp_state_s *state) interval_s = (state->delayreq_interval > 0) ? state->delayreq_interval : 1; - if (timespec_to_ms(&delta) >= interval_s * MSEC_PER_SEC) + if (timespec_to_ms(&delta) >= (int64_t)interval_s * MSEC_PER_SEC) { ptp_send_delay_req(state); } @@ -1465,7 +1465,7 @@ static int ptp_periodic_send(FAR struct ptp_state_s *state) interval_s = (state->delayreq_interval > 0) ? state->delayreq_interval : 1; - if (timespec_to_ms(&delta) >= interval_s * MSEC_PER_SEC) + if (timespec_to_ms(&delta) >= (int64_t)interval_s * MSEC_PER_SEC) { ptp_send_pdelay_req(state); } @@ -1720,8 +1720,8 @@ static int ptp_update_local_clock(FAR struct ptp_state_s *state, * current phase error. */ - adjustment_ns = state->drift_ppb * CONFIG_CLOCK_ADJTIME_PERIOD_MS - / MSEC_PER_SEC; + adjustment_ns = (int64_t)state->drift_ppb * + CONFIG_CLOCK_ADJTIME_PERIOD_MS / MSEC_PER_SEC; adjustment_ns += delta_ns; }
