Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static code analysis _032 (Coercion Alters Value - offsetScaledLogVariance) #65

Open
PawelModrzejewski opened this issue Dec 17, 2020 · 0 comments

Comments

@PawelModrzejewski
Copy link
Contributor

Short summary (details in attached file):

buildPTPMessage()
.../common/ptp_message.cpp

PTPMessageCommon *buildPTPMessage
( char *buf, int size, LinkLayerAddress *remote,
  CommonPort *port )
{
...
                    annc->
                      grandmasterClockQuality->offsetScaledLogVariance =
                      	
Coercion Alters Value help
PLAT_ntohs(...) is coerced from unsigned short to short.

                      PLAT_ntohs 
                      ( annc->grandmasterClockQuality->
                        offsetScaledLogVariance );

PLAT_ntohs()
.../linux/src/platform.cpp
uint16_t PLAT_ntohs( uint16_t s ) {
        return ntohs( s );
}        	

SCA complains here about ntohs() but I believe the real issue is the type of offsetScaledLogVariance in struct ClockQuality, 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 later in the code examples.

gptp_032.txt

PawelModrzejewski added a commit to PawelModrzejewski/gptp that referenced this issue Jan 21, 2021
Static code analysis fix _032 (Issue Avnu#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.
MarcinMiklas added a commit that referenced this issue Mar 3, 2023
…gVariance_int_to_uint

offsetScaledLogVariance: change it to unsigned short (SCA _032 #65)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant