Skip to content

Commit ef14a08

Browse files
Fix declarations after statements (#1106)
* Fix C90: Wno-declaration-after-statement * Uncrustify: triggered by comment --------- Co-authored-by: GitHub Action <[email protected]>
1 parent 31ac992 commit ef14a08

18 files changed

+101
-86
lines changed

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@ add_compile_options(
217217
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-extra-semi-stmt>
218218
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-missing-noreturn>
219219
$<$<COMPILE_LANG_AND_ID:C,Clang>:-Wno-cast-align>
220-
221-
# Suppressions required to build clean with GCC.
222-
$<$<COMPILE_LANG_AND_ID:C,GNU>:-Wno-declaration-after-statement>
223220
)
224221

225222
########################################################################

source/FreeRTOS_DHCP.c

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,20 +1378,14 @@
13781378
uint8_t * pucUDPPayloadBuffer = NULL;
13791379

13801380
#if ( ipconfigDHCP_REGISTER_HOSTNAME == 1 )
1381-
const char * pucHostName = pcApplicationHostnameHook();
13821381
size_t uxNameLength = 0;
1382+
const char * pucHostName = pcApplicationHostnameHook();
13831383

13841384
if( pucHostName != NULL )
13851385
{
13861386
uxNameLength = strlen( pucHostName );
13871387
}
13881388

1389-
uint8_t * pucPtr;
1390-
1391-
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
1392-
const void * pvCopySource;
1393-
void * pvCopyDest;
1394-
13951389
/* Two extra bytes for option code and length. */
13961390
uxRequiredBufferSize += ( 2U + uxNameLength );
13971391
#endif /* if ( ipconfigDHCP_REGISTER_HOSTNAME == 1 ) */
@@ -1402,6 +1396,8 @@
14021396

14031397
if( pxNetworkBuffer != NULL )
14041398
{
1399+
uint8_t * pucIPType;
1400+
14051401
/* Leave space for the UDP header. */
14061402
pucUDPPayloadBuffer = &( pxNetworkBuffer->pucEthernetBuffer[ ipUDP_PAYLOAD_OFFSET_IPv4 ] );
14071403

@@ -1410,20 +1406,16 @@
14101406
/* coverity[misra_c_2012_rule_11_3_violation] */
14111407
pxDHCPMessage = ( ( DHCPMessage_IPv4_t * ) pucUDPPayloadBuffer );
14121408

1413-
{
1414-
uint8_t * pucIPType;
1415-
1416-
/* Store the IP type at a known location.
1417-
* Later the type must be known to translate
1418-
* a payload- to a network buffer.
1419-
*/
1409+
/* Store the IP type at a known location.
1410+
* Later the type must be known to translate
1411+
* a payload- to a network buffer.
1412+
*/
14201413

1421-
/* MISRA Ref 18.4.1 [Usage of +, -, += and -= operators on expression of pointer type]. */
1422-
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-184. */
1423-
/* coverity[misra_c_2012_rule_18_4_violation] */
1424-
pucIPType = pucUDPPayloadBuffer - ipUDP_PAYLOAD_IP_TYPE_OFFSET;
1425-
*pucIPType = ipTYPE_IPv4;
1426-
}
1414+
/* MISRA Ref 18.4.1 [Usage of +, -, += and -= operators on expression of pointer type]. */
1415+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-184. */
1416+
/* coverity[misra_c_2012_rule_18_4_violation] */
1417+
pucIPType = pucUDPPayloadBuffer - ipUDP_PAYLOAD_IP_TYPE_OFFSET;
1418+
*pucIPType = ipTYPE_IPv4;
14271419

14281420
/* Most fields need to be zero. */
14291421
( void ) memset( pxDHCPMessage, 0x00, sizeof( DHCPMessage_IPv4_t ) );
@@ -1455,7 +1447,7 @@
14551447
* it easier to lookup a device in a router's list of DHCP clients. */
14561448

14571449
/* Point to where the OPTION_END was stored to add data. */
1458-
pucPtr = &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + ( *pxOptionsArraySize - 1U ) ] );
1450+
uint8_t * pucPtr = &( pucUDPPayloadBuffer[ dhcpFIRST_OPTION_BYTE_OFFSET + ( *pxOptionsArraySize - 1U ) ] );
14591451
pucPtr[ 0U ] = dhcpIPv4_DNS_HOSTNAME_OPTIONS_CODE;
14601452
pucPtr[ 1U ] = ( uint8_t ) uxNameLength;
14611453

@@ -1466,8 +1458,9 @@
14661458
*/
14671459
if( pucHostName != NULL )
14681460
{
1469-
pvCopySource = pucHostName;
1470-
pvCopyDest = &pucPtr[ 2U ];
1461+
/* memcpy() helper variables for MISRA Rule 21.15 compliance*/
1462+
const void * pvCopySource = pucHostName;
1463+
void * pvCopyDest = &pucPtr[ 2U ];
14711464

14721465
( void ) memcpy( pvCopyDest, pvCopySource, uxNameLength );
14731466
}

source/FreeRTOS_DHCPv6.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,18 @@ static void prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint )
10041004

10051005
if( ucMessageType != 0U )
10061006
{
1007+
/* DHCPv6_Option_IA_for_Prefix_Delegation */
1008+
uint32_t ulIAID = 0x27fe8f95;
1009+
uint32_t ulTime_1 = 3600U;
1010+
uint32_t ulTime_2 = 5400U;
1011+
1012+
/* DHCPv6_Option_IA_Prefix */
1013+
uint32_t ulPreferredLifeTime = 4500U;
1014+
uint32_t ulPValidLifeTime = 7200U;
1015+
uint8_t ucPrefixLength = ( uint8_t ) pxEndPoint->ipv6_settings.uxPrefixLength;
1016+
1017+
struct freertos_sockaddr * pxAddress;
1018+
10071019
vBitConfig_write_8( &( xMessage ), ucMessageType ); /* 1 Solicit, 3, request */
10081020
vBitConfig_write_uc( &( xMessage ), pxDHCPMessage->ucTransactionID, 3 );
10091021

@@ -1040,25 +1052,15 @@ static void prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint )
10401052
}
10411053

10421054
/* DHCPv6_Option_Elapsed_Time */
1043-
vBitConfig_write_16( &( xMessage ), DHCPv6_Option_Elapsed_Time ); /* usOption; Option is 8 * / */
1044-
vBitConfig_write_16( &( xMessage ), 2U ); /* usLength; length is 2 * / */
1045-
vBitConfig_write_16( &( xMessage ), 0x0000 ); /* usTime; 00 00 : 0 ms. * / */
1055+
vBitConfig_write_16( &( xMessage ), DHCPv6_Option_Elapsed_Time ); /* usOption; Option is 8 * / */
1056+
vBitConfig_write_16( &( xMessage ), 2U ); /* usLength; length is 2 * / */
1057+
vBitConfig_write_16( &( xMessage ), 0x0000 ); /* usTime; 00 00 : 0 ms. * / */
10461058

1047-
/* DHCPv6_Option_IA_for_Prefix_Delegation */
1048-
uint32_t ulIAID = 0x27fe8f95;
1049-
uint32_t ulTime_1 = 3600U;
1050-
uint32_t ulTime_2 = 5400U;
1051-
1052-
vBitConfig_write_16( &( xMessage ), DHCPv6_Option_IA_for_Prefix_Delegation ); /* usOption; Option is 25 */
1053-
vBitConfig_write_16( &( xMessage ), 41 ); /* usLength; length is 12 + 29 = 41 */
1054-
vBitConfig_write_32( &( xMessage ), ulIAID ); /* 27 fe 8f 95. */
1055-
vBitConfig_write_32( &( xMessage ), ulTime_1 ); /* 00 00 0e 10: 3600 sec */
1056-
vBitConfig_write_32( &( xMessage ), ulTime_2 ); /* 00 00 15 18: 5400 sec */
1057-
1058-
/* DHCPv6_Option_IA_Prefix */
1059-
uint32_t ulPreferredLifeTime = 4500U;
1060-
uint32_t ulPValidLifeTime = 7200U;
1061-
uint8_t ucPrefixLength = ( uint8_t ) pxEndPoint->ipv6_settings.uxPrefixLength;
1059+
vBitConfig_write_16( &( xMessage ), DHCPv6_Option_IA_for_Prefix_Delegation ); /* usOption; Option is 25 */
1060+
vBitConfig_write_16( &( xMessage ), 41 ); /* usLength; length is 12 + 29 = 41 */
1061+
vBitConfig_write_32( &( xMessage ), ulIAID ); /* 27 fe 8f 95. */
1062+
vBitConfig_write_32( &( xMessage ), ulTime_1 ); /* 00 00 0e 10: 3600 sec */
1063+
vBitConfig_write_32( &( xMessage ), ulTime_2 ); /* 00 00 15 18: 5400 sec */
10621064

10631065
vBitConfig_write_16( &( xMessage ), DHCPv6_Option_IA_Prefix ); /* usOption Option is 26 */
10641066
vBitConfig_write_16( &( xMessage ), 25 ); /* usLength length is 25 */
@@ -1085,7 +1087,7 @@ static void prvSendDHCPMessage( NetworkEndPoint_t * pxEndPoint )
10851087
xAddress.sin_family = FREERTOS_AF_INET6;
10861088
xAddress.sin_port = FreeRTOS_htons( ipDHCPv6_SERVER_PORT );
10871089

1088-
struct freertos_sockaddr * pxAddress = &( xAddress );
1090+
pxAddress = &( xAddress );
10891091

10901092
FreeRTOS_printf( ( "DHCP Sending request %u.\n", ucMessageType ) );
10911093
( void ) FreeRTOS_sendto( EP_DHCPData.xDHCPSocket, ( const void * ) xMessage.ucContents, xMessage.uxIndex, 0, pxAddress, sizeof xAddress );

source/FreeRTOS_DNS.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,13 @@
836836
{
837837
NetworkEndPoint_t * pxEndPoint = NULL;
838838

839+
/* If LLMNR is being used then determine if the host name includes a '.' -
840+
* if not then LLMNR can be used as the lookup method. */
841+
/* For local resolution, mDNS uses names ending with the string ".local" */
842+
BaseType_t bHasDot = pdFALSE;
843+
BaseType_t bHasLocal = pdFALSE;
844+
const char * pcDot = ( const char * ) strchr( pcHostName, ( int32_t ) '.' );
845+
839846
#if ( ipconfigUSE_MDNS == 1 ) || ( ipconfigUSE_LLMNR == 1 )
840847
BaseType_t xNeed_Endpoint = pdFALSE;
841848
#endif
@@ -857,13 +864,6 @@
857864
/* Use the DNS port by default, this may be changed later. */
858865
pxAddress->sin_port = dnsDNS_PORT;
859866

860-
/* If LLMNR is being used then determine if the host name includes a '.' -
861-
* if not then LLMNR can be used as the lookup method. */
862-
/* For local resolution, mDNS uses names ending with the string ".local" */
863-
BaseType_t bHasDot = pdFALSE;
864-
BaseType_t bHasLocal = pdFALSE;
865-
const char * pcDot = ( const char * ) strchr( pcHostName, ( int32_t ) '.' );
866-
867867
if( pcDot != NULL )
868868
{
869869
bHasDot = pdTRUE;
@@ -1007,9 +1007,10 @@
10071007

10081008
if( pxEndPoint->bits.bIPv6 == 0U )
10091009
{
1010+
uint32_t ulIPAddress;
10101011
uint8_t ucIndex = pxEndPoint->ipv4_settings.ucDNSIndex;
10111012
configASSERT( ucIndex < ipconfigENDPOINT_DNS_ADDRESS_COUNT );
1012-
uint32_t ulIPAddress = pxEndPoint->ipv4_settings.ulDNSServerAddresses[ ucIndex ];
1013+
ulIPAddress = pxEndPoint->ipv4_settings.ulDNSServerAddresses[ ucIndex ];
10131014

10141015
if( ( ulIPAddress != 0U ) && ( ulIPAddress != ipBROADCAST_IP_ADDRESS ) )
10151016
{
@@ -1027,9 +1028,10 @@
10271028

10281029
if( pxEndPoint->bits.bIPv6 != 0U )
10291030
{
1031+
const uint8_t * ucBytes;
10301032
uint8_t ucIndex = pxEndPoint->ipv6_settings.ucDNSIndex;
10311033
configASSERT( ucIndex < ipconfigENDPOINT_DNS_ADDRESS_COUNT );
1032-
const uint8_t * ucBytes = pxEndPoint->ipv6_settings.xDNSServerAddresses[ ucIndex ].ucBytes;
1034+
ucBytes = pxEndPoint->ipv6_settings.xDNSServerAddresses[ ucIndex ].ucBytes;
10331035

10341036
/* Test if the DNS entry is in used. */
10351037
if( ( ucBytes[ 0 ] != 0U ) && ( ucBytes[ 1 ] != 0U ) )
@@ -1171,6 +1173,10 @@
11711173

11721174
if( xDNSBuf.pucPayloadBuffer != NULL )
11731175
{
1176+
/* A two-step conversion to conform to MISRA. */
1177+
size_t uxIndex = ipUDP_PAYLOAD_IP_TYPE_OFFSET;
1178+
BaseType_t xIndex = ( BaseType_t ) uxIndex;
1179+
11741180
#if ( ipconfigUSE_LLMNR == 1 )
11751181
{
11761182
if( FreeRTOS_ntohs( pxAddress->sin_port ) == ipLLMNR_PORT )
@@ -1183,10 +1189,6 @@
11831189
}
11841190
#endif
11851191

1186-
/* A two-step conversion to conform to MISRA. */
1187-
size_t uxIndex = ipUDP_PAYLOAD_IP_TYPE_OFFSET;
1188-
BaseType_t xIndex = ( BaseType_t ) uxIndex;
1189-
11901192
/* Later when translating form UDP payload to a Network Buffer,
11911193
* it is important to know whether this is an IPv4 packet. */
11921194
if( pxAddress->sin_family == ( uint8_t ) FREERTOS_AF_INET6 )

source/FreeRTOS_IP.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,7 @@ void * FreeRTOS_GetUDPPayloadBuffer_Multi( size_t uxRequestedSizeBytes,
876876

877877
if( pxNetworkBuffer != NULL )
878878
{
879+
uint8_t * pucIPType;
879880
size_t uxIndex = ipUDP_PAYLOAD_IP_TYPE_OFFSET;
880881
BaseType_t xPayloadIPTypeOffset = ( BaseType_t ) uxIndex;
881882

@@ -885,8 +886,6 @@ void * FreeRTOS_GetUDPPayloadBuffer_Multi( size_t uxRequestedSizeBytes,
885886
/* Skip 3 headers. */
886887
pvReturn = ( void * ) &( pxNetworkBuffer->pucEthernetBuffer[ uxPayloadOffset ] );
887888

888-
uint8_t * pucIPType;
889-
890889
/* Later a pointer to a UDP payload is used to retrieve a NetworkBuffer.
891890
* Store the packet type at 48 bytes before the start of the UDP payload. */
892891
pucIPType = ( uint8_t * ) pvReturn;

source/FreeRTOS_IP_Utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,10 @@ uint16_t usGenerateProtocolChecksum( uint8_t * pucEthernetBuffer,
10711071
{
10721072
struct xPacketSummary xSet;
10731073

1074-
( void ) memset( &( xSet ), 0, sizeof( xSet ) );
1075-
10761074
DEBUG_DECLARE_TRACE_VARIABLE( BaseType_t, xLocation, 0 );
10771075

1076+
( void ) memset( &( xSet ), 0, sizeof( xSet ) );
1077+
10781078
#if ( ipconfigHAS_DEBUG_PRINTF != 0 )
10791079
{
10801080
xSet.pcType = "???";

source/FreeRTOS_IPv4_Utils.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ BaseType_t prvChecksumIPv4Checks( uint8_t * pucEthernetBuffer,
124124

125125
if( xReturn == 0 )
126126
{
127+
size_t uxNeeded;
127128
/* xIPHeader.usLength is the total length, minus the Ethernet header. */
128129
pxSet->usPayloadLength = FreeRTOS_ntohs( pxSet->pxIPPacket->xIPHeader.usLength );
129130

130-
size_t uxNeeded = pxSet->usPayloadLength;
131+
uxNeeded = pxSet->usPayloadLength;
131132
uxNeeded += ipSIZE_OF_ETH_HEADER;
132133

133134
if( uxBufferLength < uxNeeded )

source/FreeRTOS_IPv6_Utils.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ BaseType_t prvChecksumIPv6Checks( uint8_t * pucEthernetBuffer,
100100
}
101101
else
102102
{
103+
size_t uxNeeded;
104+
103105
/* MISRA Ref 11.3.1 [Misaligned access] */
104106
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Plus-TCP/blob/main/MISRA.md#rule-113 */
105107
/* coverity[misra_c_2012_rule_11_3_violation] */
@@ -108,7 +110,7 @@ BaseType_t prvChecksumIPv6Checks( uint8_t * pucEthernetBuffer,
108110
/* For IPv6, the number of bytes in the protocol is indicated. */
109111
pxSet->usProtocolBytes = ( uint16_t ) ( pxSet->usPayloadLength - uxExtensionHeaderLength );
110112

111-
size_t uxNeeded = ( size_t ) pxSet->usPayloadLength;
113+
uxNeeded = ( size_t ) pxSet->usPayloadLength;
112114
uxNeeded += ipSIZE_OF_ETH_HEADER + ipSIZE_OF_IPv6_HEADER;
113115

114116
if( uxBufferLength < uxNeeded )

source/FreeRTOS_ND.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,10 +924,11 @@
924924

925925
if( memcmp( pxIPv6Address->ucBytes, pxIPHeader->xSourceAddress.ucBytes, ipSIZE_OF_IPv6_ADDRESS ) == 0 )
926926
{
927-
FreeRTOS_printf( ( "Waiting done\n" ) );
928927
IPStackEvent_t xEventMessage;
929928
const TickType_t xDontBlock = ( TickType_t ) 0;
930929

930+
FreeRTOS_printf( ( "Waiting done\n" ) );
931+
931932
xEventMessage.eEventType = eNetworkRxEvent;
932933
xEventMessage.pvData = ( void * ) pxARPWaitingNetworkBuffer;
933934

@@ -1269,6 +1270,7 @@
12691270

12701271
if( xResult == pdPASS )
12711272
{
1273+
size_t uxIndex;
12721274
/* A loopback IP-address has a prefix of 128. */
12731275
configASSERT( ( uxPrefixLength > 0U ) && ( uxPrefixLength <= ( 8U * ipSIZE_OF_IPv6_ADDRESS ) ) );
12741276

@@ -1278,7 +1280,7 @@
12781280
}
12791281

12801282
pucSource = ( uint8_t * ) pulRandom;
1281-
size_t uxIndex = uxPrefixLength / 8U;
1283+
uxIndex = uxPrefixLength / 8U;
12821284

12831285
if( ( uxPrefixLength % 8U ) != 0U )
12841286
{

source/FreeRTOS_RA.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,15 @@
642642
{
643643
TickType_t uxReloadTime = pdMS_TO_TICKS( 5000U );
644644

645+
#if ( ipconfigHAS_PRINTF == 1 )
646+
eRAState_t eRAState;
647+
#endif
648+
645649
configASSERT( pxEndPoint != NULL );
646650

647651
#if ( ipconfigHAS_PRINTF == 1 )
648652
/* Remember the initial state, just for logging. */
649-
eRAState_t eRAState = pxEndPoint->xRAData.eRAState;
653+
eRAState = pxEndPoint->xRAData.eRAState;
650654
#endif
651655

652656
if( xDoReset != pdFALSE )

0 commit comments

Comments
 (0)