From 0c70f249c3be7c2bbb25ed18c4b96b05b9496526 Mon Sep 17 00:00:00 2001 From: Jason Valenzuela Date: Tue, 17 Mar 2020 23:20:02 -0400 Subject: [PATCH] Add assertions and casts to implicit integer demotions. Resolves Visual Studio warnings about data loss when implicitly converting integers to smaller sizes. --- source/src/cip/cipepath.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/src/cip/cipepath.c b/source/src/cip/cipepath.c index 4dafe37bf..c168cdfb1 100644 --- a/source/src/cip/cipepath.c +++ b/source/src/cip/cipepath.c @@ -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 */