From 2a06af56fa0f5bcaa193d504022b75d0fcc1a116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Modrzejewski?= Date: Thu, 21 Jan 2021 16:47:25 +0100 Subject: [PATCH] offsetScaledLogVariance: change it to unsigned short (SCA _032 #65) Static code analysis fix _032 (Issue #65) SCA complains here about ntohs() but the real issue is the type of offsetScaledLogVariance, which currently in the code is int16_t. There seems to be inconsistency in IEEE 802.1AS-2011: - in 6.3.3.8 ClockQuality offsetScaledLogVariance is defined as UInteger16; - later in the document it's used as Integer16 (Table 14-1, code examples etc.); This inconsistency has been corrected in IEEE 802.1AS-2011/Cor 1-2013 where UInteger16 was specified in the Table 14-1 and used later in the code examples. --- common/avbts_clock.hpp | 2 +- common/avbts_osipc.hpp | 2 +- common/ipcdef.hpp | 2 +- linux/shm_test/shm_test.cpp | 2 +- linux/src/linux_hal_common.cpp | 2 +- linux/src/linux_hal_common.hpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/common/avbts_clock.hpp b/common/avbts_clock.hpp index 22a7246..b817a5a 100644 --- a/common/avbts_clock.hpp +++ b/common/avbts_clock.hpp @@ -78,7 +78,7 @@ struct ClockQuality { unsigned char clockAccuracy; /*!< Clock Accuracy - clause 8.6.2.3. Indicates the expected time accuracy of a clock master.*/ - int16_t offsetScaledLogVariance; /*!< ::Offset Scaled log variance - Clause 8.6.2.4. + uint16_t offsetScaledLogVariance; /*!< ::Offset Scaled log variance - Clause 8.6.2.4. Is the scaled, offset representation of an estimate of the PTP variance. The PTP variance characterizes the diff --git a/common/avbts_osipc.hpp b/common/avbts_osipc.hpp index 2adb3db..22e96c4 100644 --- a/common/avbts_osipc.hpp +++ b/common/avbts_osipc.hpp @@ -119,7 +119,7 @@ class OS_IPC { uint8_t clock_identity[], uint8_t priority1, uint8_t clock_class, - int16_t offset_scaled_log_variance, + uint16_t offset_scaled_log_variance, uint8_t clock_accuracy, uint8_t priority2, uint8_t domain_number, diff --git a/common/ipcdef.hpp b/common/ipcdef.hpp index 670aeee..1854fc4 100644 --- a/common/ipcdef.hpp +++ b/common/ipcdef.hpp @@ -82,7 +82,7 @@ typedef struct { uint8_t clock_identity[PTP_CLOCK_IDENTITY_LENGTH]; //!< The clock identity of the interface uint8_t priority1; //!< The priority1 field of the grandmaster functionality of the interface, or 0xFF if not supported uint8_t clock_class; //!< The clockClass field of the grandmaster functionality of the interface, or 0xFF if not supported - int16_t offset_scaled_log_variance; //!< The offsetScaledLogVariance field of the grandmaster functionality of the interface, or 0x0000 if not supported + uint16_t offset_scaled_log_variance; //!< The offsetScaledLogVariance field of the grandmaster functionality of the interface, or 0x0000 if not supported uint8_t clock_accuracy; //!< The clockAccuracy field of the grandmaster functionality of the interface, or 0xFF if not supported uint8_t priority2; //!< The priority2 field of the grandmaster functionality of the interface, or 0xFF if not supported uint8_t domain_number; //!< The domainNumber field of the grandmaster functionality of the interface, or 0 if not supported diff --git a/linux/shm_test/shm_test.cpp b/linux/shm_test/shm_test.cpp index dbe01c5..4348ea1 100644 --- a/linux/shm_test/shm_test.cpp +++ b/linux/shm_test/shm_test.cpp @@ -113,7 +113,7 @@ int main(int argc, char *argv[]) (unsigned int) ptpData->clock_identity[6], (unsigned int) ptpData->clock_identity[7]); fprintf(stdout, "priority1 %u\n", (unsigned int) ptpData->priority1); fprintf(stdout, "clock_class %u\n", (unsigned int) ptpData->clock_class); - fprintf(stdout, "offset_scaled_log_variance %d\n", (int) ptpData->offset_scaled_log_variance); + fprintf(stdout, "offset_scaled_log_variance %d\n", (unsigned int) ptpData->offset_scaled_log_variance); fprintf(stdout, "clock_accuracy %u\n", (unsigned int) ptpData->clock_accuracy); fprintf(stdout, "priority2 %u\n", (unsigned int) ptpData->priority2); fprintf(stdout, "domain_number %u\n", (unsigned int) ptpData->domain_number); diff --git a/linux/src/linux_hal_common.cpp b/linux/src/linux_hal_common.cpp index b651b88..cb3a13a 100644 --- a/linux/src/linux_hal_common.cpp +++ b/linux/src/linux_hal_common.cpp @@ -992,7 +992,7 @@ bool LinuxSharedMemoryIPC::update_network_interface( uint8_t clock_identity[], uint8_t priority1, uint8_t clock_class, - int16_t offset_scaled_log_variance, + uint16_t offset_scaled_log_variance, uint8_t clock_accuracy, uint8_t priority2, uint8_t domain_number, diff --git a/linux/src/linux_hal_common.hpp b/linux/src/linux_hal_common.hpp index d6aa651..14d20b2 100644 --- a/linux/src/linux_hal_common.hpp +++ b/linux/src/linux_hal_common.hpp @@ -706,7 +706,7 @@ class LinuxSharedMemoryIPC:public OS_IPC { uint8_t clock_identity[], uint8_t priority1, uint8_t clock_class, - int16_t offset_scaled_log_variance, + uint16_t offset_scaled_log_variance, uint8_t clock_accuracy, uint8_t priority2, uint8_t domain_number,