Skip to content

Commit b23fa86

Browse files
authored
Add and fix -Wconversion errors (#980)
* Fix Wconverstion * Enable Wconversion warning * Add fix * Fix MISRA * Fix coverity * Add comments
1 parent 14b3e24 commit b23fa86

20 files changed

+57
-47
lines changed

CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,16 @@ add_compile_options(
196196
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wall>
197197
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wextra>
198198
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Werror>
199+
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wconversion>
199200
$<$<COMPILE_LANG_AND_ID:C,Clang,GNU>:-Wunused-variable>
200201
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Weverything>
201202

202-
# TODO: Add in other Compilers here.
203+
# Suppressions required to build clean with clang.
204+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-unused-macros>
205+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-padded>
206+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-variable-declarations>
207+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-covered-switch-default>
208+
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-align>
203209
)
204210

205211
########################################################################

source/FreeRTOS_ARP.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,10 @@ static TickType_t xLastGratuitousARPTime = 0U;
321321
}
322322
}
323323
}
324+
else
325+
{
326+
/* do nothing, coverity happy */
327+
}
324328

325329
break;
326330

source/FreeRTOS_BitConfig.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ uint16_t usBitConfig_read_16( BitConfig_t * pxConfig )
200200

201201
if( xBitConfig_read_uc( pxConfig, pucData, uxNeeded ) != pdFALSE )
202202
{
203-
usResult = ( ( ( uint16_t ) pucData[ 0 ] ) << 8 ) |
204-
( ( ( uint16_t ) pucData[ 1 ] ) );
203+
usResult = ( uint16_t ) ( ( ( ( uint16_t ) pucData[ 0 ] ) << 8 ) |
204+
( ( ( uint16_t ) pucData[ 1 ] ) ) );
205205
}
206206

207207
return usResult;

source/FreeRTOS_DHCP.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,8 +1654,8 @@
16541654

16551655
( void ) xApplicationGetRandomNumber( &( ulNumbers[ 0 ] ) );
16561656
( void ) xApplicationGetRandomNumber( &( ulNumbers[ 1 ] ) );
1657-
ucLinkLayerIPAddress[ 0 ] = ( uint8_t ) 1 + ( uint8_t ) ( ulNumbers[ 0 ] % 0xFDU ); /* get value 1..254 for IP-address 3rd byte of IP address to try. */
1658-
ucLinkLayerIPAddress[ 1 ] = ( uint8_t ) 1 + ( uint8_t ) ( ulNumbers[ 1 ] % 0xFDU ); /* get value 1..254 for IP-address 4th byte of IP address to try. */
1657+
ucLinkLayerIPAddress[ 0 ] = ( uint8_t ) ( 1 + ( ulNumbers[ 0 ] % 0xFDU ) ); /* get value 1..254 for IP-address 3rd byte of IP address to try. */
1658+
ucLinkLayerIPAddress[ 1 ] = ( uint8_t ) ( 1 + ( ulNumbers[ 1 ] % 0xFDU ) ); /* get value 1..254 for IP-address 4th byte of IP address to try. */
16591659

16601660
EP_IPv4_SETTINGS.ulGatewayAddress = 0U;
16611661

source/FreeRTOS_DHCPv6.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ static void prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint )
10111011
uint16_t usLength = ( uint16_t ) pxDHCPMessage->xServerID.uxLength;
10121012
/* DHCPv6_Option_Server_Identifier */
10131013
vBitConfig_write_16( &( xMessage ), DHCPv6_Option_Server_Identifier ); /* Option is 1: Server Identifier */
1014-
vBitConfig_write_16( &( xMessage ), usLength + 4U ); /* The length is 14 */
1014+
vBitConfig_write_16( &( xMessage ), ( uint16_t ) ( usLength + 4U ) ); /* The length is 14 */
10151015
vBitConfig_write_16( &( xMessage ), pxDHCPMessage->xServerID.usDUIDType ); /* The type of DUID: 1, 2, or 3. */
10161016
vBitConfig_write_16( &( xMessage ), pxDHCPMessage->xServerID.usHardwareType );
10171017
vBitConfig_write_uc( &( xMessage ), pxDHCPMessage->xServerID.pucID, pxDHCPMessage->xServerID.uxLength );
@@ -1263,7 +1263,7 @@ static BaseType_t prvDHCPv6_handleOption( struct xNetworkEndPoint * pxEndPoint,
12631263
* - the message does not include a Client Identifier option.
12641264
* - the contents of the Client Identifier option does not match the client's DUID.
12651265
* - the "transaction-id" field value does not match the value the client used in its Solicit message. */
1266-
( void ) xBitConfig_read_uc( pxMessage, pxDHCPMessage->xClientID.pucID, lIDSize ); /* Link Layer address, 6 bytes */
1266+
( void ) xBitConfig_read_uc( pxMessage, pxDHCPMessage->xClientID.pucID, ( size_t ) lIDSize ); /* Link Layer address, 6 bytes */
12671267

12681268
/* Check client DUID. */
12691269
if( ( pxSet->uxOptionLength != dhcpIPv6_CLIENT_DUID_LENGTH ) ||

source/FreeRTOS_DNS_Parser.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@
471471
/*logging*/
472472
FreeRTOS_printf( ( "prvParseDNS_HandleLLMNRRequest[%s]: type %04X\n", xSet.pcName, xSet.usType ) );
473473

474-
xEndPoint.usDNSType = xSet.usType;
474+
xEndPoint.usDNSType = ( uint8_t ) xSet.usType;
475475
}
476476
#endif /* ( ipconfigUSE_IPv6 != 0 ) */
477477

@@ -572,7 +572,7 @@
572572
( void ) memcpy( &( pxAnswer->ulIPAddress ), xEndPoint.ipv6_settings.xIPAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS );
573573
uxDistance = ( size_t ) ( xSet.pucByte - pucNewBuffer );
574574
/* An extra 12 bytes will be sent compared to an A-record. */
575-
usLength = ( int16_t ) sizeof( *pxAnswer ) + uxDistance + ipSIZE_OF_IPv6_ADDRESS - sizeof( pxAnswer->ulIPAddress );
575+
usLength = ( int16_t ) ( sizeof( *pxAnswer ) + uxDistance + ipSIZE_OF_IPv6_ADDRESS - sizeof( pxAnswer->ulIPAddress ) );
576576
}
577577
else
578578
#endif /* ( ipconfigUSE_IPv6 != 0 ) */
@@ -1090,8 +1090,8 @@
10901090
/* Define the ASCII value of the capital "A". */
10911091
const uint8_t ucCharA = ( uint8_t ) 0x41U;
10921092

1093-
ucByte = ( ( uint8_t ) ( ( pucSource[ 0 ] - ucCharA ) << 4 ) ) |
1094-
( pucSource[ 1 ] - ucCharA );
1093+
ucByte = ( uint8_t ) ( ( ( pucSource[ 0 ] - ucCharA ) << 4 ) |
1094+
( pucSource[ 1 ] - ucCharA ) );
10951095

10961096
/* Make sure there are no trailing spaces in the name. */
10971097
if( ( ucByte == ( uint8_t ) ' ' ) && ( pucTarget[ 1 ] == 0U ) )

source/FreeRTOS_IPv4.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,8 @@ eFrameProcessingResult_t prvCheckIP4HeaderOptions( NetworkBufferDescriptor_t * c
457457
pxIPHeader->usLength = FreeRTOS_htons( FreeRTOS_ntohs( pxIPHeader->usLength ) - optlen );
458458

459459
/* Rewrite the Version/IHL byte to indicate that this packet has no IP options. */
460-
pxIPHeader->ucVersionHeaderLength = ( pxIPHeader->ucVersionHeaderLength & 0xF0U ) | /* High nibble is the version. */
461-
( ( ipSIZE_OF_IPv4_HEADER >> 2 ) & 0x0FU );
460+
pxIPHeader->ucVersionHeaderLength = ( uint8_t ) ( ( pxIPHeader->ucVersionHeaderLength & 0xF0U ) | /* High nibble is the version. */
461+
( ( ipSIZE_OF_IPv4_HEADER >> 2 ) & 0x0FU ) );
462462
}
463463
#else /* if ( ipconfigIP_PASS_PACKETS_WITH_IP_OPTIONS != 0 ) */
464464
{

source/FreeRTOS_IPv4_Utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ BaseType_t prvChecksumIPv4Checks( uint8_t * pucEthernetBuffer,
147147
/* coverity[misra_c_2012_rule_11_3_violation] */
148148
pxSet->pxProtocolHeaders = ( ( ProtocolHeaders_t * ) &( pucEthernetBuffer[ pxSet->uxIPHeaderLength + ipSIZE_OF_ETH_HEADER ] ) );
149149
/* For IPv4, the number of bytes in IP-header + the protocol is indicated. */
150-
pxSet->usProtocolBytes = pxSet->usPayloadLength - ( ( uint16_t ) pxSet->uxIPHeaderLength );
150+
pxSet->usProtocolBytes = ( uint16_t ) ( pxSet->usPayloadLength - pxSet->uxIPHeaderLength );
151151
}
152152

153153
return xReturn;

source/FreeRTOS_IPv6.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ const struct xIPv6_Address FreeRTOS_in6addr_loopback = { { 0, 0, 0, 0, 0, 0, 0,
145145
{
146146
pxExtHeader = ( const IPExtHeader_IPv6_t * ) ( &( pucEthernetBuffer[ ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER + uxExtHeaderLength ] ) );
147147
/* The definition of length in extension header - Length of this header in 8-octet units, not including the first 8 octets. */
148-
uxExtHeaderLength += ( 8 * pxExtHeader->ucHeaderExtLength ) + 8;
148+
uxExtHeaderLength += ( size_t ) ( ( 8 * pxExtHeader->ucHeaderExtLength ) + 8 );
149149

150150
ucNextHeader = pxExtHeader->ucNextHeader;
151151

@@ -656,7 +656,7 @@ eFrameProcessingResult_t eHandleIPv6ExtensionHeaders( NetworkBufferDescriptor_t
656656
( void ) memmove( pucTo, pucFrom, xMoveLen );
657657
pxNetworkBuffer->xDataLength -= uxRemovedBytes;
658658

659-
usPayloadLength -= ( uint16_t ) uxRemovedBytes;
659+
usPayloadLength = ( uint16_t ) ( usPayloadLength - uxRemovedBytes );
660660
pxIPPacket_IPv6->xIPHeader.usPayloadLength = FreeRTOS_htons( usPayloadLength );
661661
eResult = eProcessBuffer;
662662
}

source/FreeRTOS_IPv6_Sockets.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ char cHexToChar( uint16_t usValue )
165165

166166
if( usValue <= 9U )
167167
{
168-
cReturn += usValue;
168+
cReturn = ( char ) ( cReturn + usValue );
169169
}
170170
else if( usValue <= 15U )
171171
{
172172
cReturn = 'a';
173-
cReturn += ( usValue - 10U );
173+
cReturn = ( char ) ( cReturn + ( usValue - ( uint16_t ) 10 ) );
174174
}
175175
else
176176
{
@@ -199,7 +199,7 @@ socklen_t uxHexPrintShort( char * pcBuffer,
199199
{
200200
const size_t uxNibbleCount = 4U;
201201
size_t uxNibble;
202-
size_t uxIndex = 0U;
202+
socklen_t uxIndex = 0U;
203203
uint16_t usShifter = usValue;
204204
BaseType_t xHadNonZero = pdFALSE;
205205

@@ -223,7 +223,7 @@ socklen_t uxHexPrintShort( char * pcBuffer,
223223
uxIndex++;
224224
}
225225

226-
usShifter <<= 4;
226+
usShifter = ( uint16_t ) ( usShifter << 4 );
227227
}
228228

229229
return uxIndex;

0 commit comments

Comments
 (0)