open-dis / open-dis-cpp

C++ implementation of the IEEE-1278.1 Distributed Interactive Simulation (DIS) application protocol v6 and v7
BSD 2-Clause "Simplified" License
90 stars 65 forks source link

EntityStatePdu wrong marshalled size calculation (number of articulation parameters) #48

Closed DPD85 closed 3 years ago

DPD85 commented 3 years ago

Inside the implementation of EntityStatePdu I discovered that the marshalled size of the PDU is calculated assuming to be present always only one articulation parameter. This is true for DIS6 and DIS7.

{
   int marshalSize = 0;

   marshalSize = EntityInformationFamilyPdu::getMarshalledSize();
   marshalSize = marshalSize + _entityID.getMarshalledSize();  // _entityID
   marshalSize = marshalSize + 1;  // _forceId
   marshalSize = marshalSize + 1;  // _numberOfArticulationParameters
   marshalSize = marshalSize + _entityType.getMarshalledSize();  // _entityType
   marshalSize = marshalSize + _alternativeEntityType.getMarshalledSize();  // _alternativeEntityType
   marshalSize = marshalSize + _entityLinearVelocity.getMarshalledSize();  // _entityLinearVelocity
   marshalSize = marshalSize + _entityLocation.getMarshalledSize();  // _entityLocation
   marshalSize = marshalSize + _entityOrientation.getMarshalledSize();  // _entityOrientation
   marshalSize = marshalSize + 4;  // _entityAppearance
   marshalSize = marshalSize + _deadReckoningParameters.getMarshalledSize();  // _deadReckoningParameters
   marshalSize = marshalSize + _marking.getMarshalledSize();  // _marking
   marshalSize = marshalSize + 4;  // _capabilities

   for(unsigned long long idx=0; idx < _articulationParameters.size(); idx++)
   {
        ArticulationParameter listElement = _articulationParameters[idx];
        marshalSize = marshalSize + listElement.getMarshalledSize();
    }

    return marshalSize;
}

As is possible to see the number of articulation parameters is stubbed to one when instead it should be _articulationParameters.size().

leif81 commented 3 years ago

Thank-you for this report @DPD85 . Would you be interested in submitting a PR to fix this?

DPD85 commented 3 years ago

@leif81 I did it.

DPD85 commented 3 years ago

@leif81 It is necessary to revert this because

marshalSize = marshalSize + _articulationParameters.size(); // _numberOfArticulationParameters

this is the size of the variable containing the number of articulation parameters and not the number of articulation parameters. So if you marshal the PDU and compare the size of the buffer with the marshalled size then you will find a difference of 1 byte.

Sorry for the mistake! :-(

leif81 commented 3 years ago

Ok thanks for heads up. Can you submit a pull request? I'll merge it when it comes in.

leif81 commented 3 years ago

Or did you want the whole original pull request reverted?

DPD85 commented 3 years ago

You can revert the entire original pull request

leif81 commented 3 years ago

Thank-you @DPD85 , the revert is done now.