Skip to content

Commit

Permalink
Add assertions and casts to implicit integer demotions.
Browse files Browse the repository at this point in the history
Resolves Visual Studio warnings about data loss when implicitly
converting integers to smaller sizes.
  • Loading branch information
jvalenzuela committed Mar 6, 2024
1 parent ee59c3d commit 757d6ee
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions source/src/cip/cipepath.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,13 @@ void CipEpathSetLogicalValue(const CipDword logical_value,
CipMessageRouterResponse *const message) {
switch(logical_format) {
case kLogicalSegmentLogicalFormatEightBit:
AddSintToMessage(logical_value, &message->message);
OPENER_ASSERT( (logical_value <= UINT8_MAX) ); /* Sanity check before casting to a smaller integer. */
AddSintToMessage( (EipUint8)logical_value, &message->message );
break;
case kLogicalSegmentLogicalFormatSixteenBit:
MoveMessageNOctets(1, &message->message); /* Needed for padding */
AddIntToMessage(logical_value, &message->message);
OPENER_ASSERT( (logical_value <= UINT16_MAX) ); /* Sanity check before casting to a smaller integer. */
AddIntToMessage( (EipUint16)logical_value, &message->message );
break;
case kLogicalSegmentLogicalFormatThirtyTwoBit:
MoveMessageNOctets(1, &message->message); /* Needed for padding */
Expand Down

0 comments on commit 757d6ee

Please sign in to comment.