Skip to content

Commit 71d6f60

Browse files
chinglee-iotUbuntu
andauthored
Fix MISRA C 2012 deviations (#165)
* Adding "UNITTEST" and "COV_ANALYSIS" to align FreeRTOS libraries design * Fix rule 12.3 not to use comma operator * Fix rule 13.4 not to use the returned value of the assignment operator * Fix rule 17.7 for unused return value * Fix rule 18.4 not to use arithmetic on pointer type * Fix rule 2.2 to remove overwritten initialized value * Fix forward NULL warning --------- Co-authored-by: Ubuntu <ubuntu@ip-172-31-34-245.ap-northeast-1.compute.internal>
1 parent df553bd commit 71d6f60

15 files changed

Lines changed: 256 additions & 242 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
cmake -S test -B build/ \
2727
-G "Unix Makefiles" \
2828
-DCMAKE_BUILD_TYPE=Debug \
29+
-DUNITTEST=ON \
2930
-DBUILD_CLONE_SUBMODULES=ON \
3031
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Werror -DNDEBUG'
3132

docs/doxygen/include/size_table.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</tr>
1010
<tr>
1111
<td>cellular_3gpp_api.c</td>
12-
<td><center>6.5K</center></td>
12+
<td><center>6.4K</center></td>
1313
<td><center>5.9K</center></td>
1414
</tr>
1515
<tr>
@@ -39,12 +39,12 @@
3939
</tr>
4040
<tr>
4141
<td>cellular_pktio.c</td>
42-
<td><center>2.2K</center></td>
43-
<td><center>1.9K</center></td>
42+
<td><center>2.3K</center></td>
43+
<td><center>2.0K</center></td>
4444
</tr>
4545
<tr>
4646
<td><b>Total estimates</b></td>
4747
<td><b><center>15.1K</center></b></td>
48-
<td><b><center>13.7K</center></b></td>
48+
<td><b><center>13.8K</center></b></td>
4949
</tr>
5050
</table>

source/cellular_3gpp_api.c

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ static bool _parseCopsNetworkNameToken( const char * pToken,
983983
{
984984
( void ) strncpy( pOperatorInfo->plmnInfo.mcc, pToken, CELLULAR_MCC_MAX_SIZE );
985985
pOperatorInfo->plmnInfo.mcc[ CELLULAR_MCC_MAX_SIZE ] = '\0';
986-
( void ) strncpy( pOperatorInfo->plmnInfo.mnc, &pToken[ CELLULAR_MCC_MAX_SIZE ],
986+
( void ) strncpy( pOperatorInfo->plmnInfo.mnc, &( pToken[ CELLULAR_MCC_MAX_SIZE ] ),
987987
( uint32_t ) ( mccMncLen - CELLULAR_MCC_MAX_SIZE + 1u ) );
988988
pOperatorInfo->plmnInfo.mnc[ CELLULAR_MNC_MAX_SIZE ] = '\0';
989989
}
@@ -1419,8 +1419,8 @@ static CellularError_t atcmdUpdateMccMnc( CellularContext_t * pContext,
14191419
CellularAtReq_t atCopsRequest = { 0 };
14201420

14211421
/* Set the response to numeric format. */
1422-
atCopsRequest.pAtCmd = "AT+COPS=3,2",
1423-
atCopsRequest.atCmdType = CELLULAR_AT_NO_RESULT,
1422+
atCopsRequest.pAtCmd = "AT+COPS=3,2";
1423+
atCopsRequest.atCmdType = CELLULAR_AT_NO_RESULT;
14241424
pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atCopsRequest );
14251425

14261426
if( pktStatus == CELLULAR_PKT_STATUS_OK )
@@ -1482,7 +1482,7 @@ static CellularError_t atcmdQueryRegStatus( CellularContext_t * pContext,
14821482
/* Get the service status from lib AT data. */
14831483
if( cellularStatus == CELLULAR_SUCCESS )
14841484
{
1485-
pLibAtData = &pContext->libAtData;
1485+
pLibAtData = &( pContext->libAtData );
14861486
_Cellular_LockAtDataMutex( pContext );
14871487
pServiceStatus->rat = pLibAtData->rat;
14881488
pServiceStatus->csRegistrationStatus = pLibAtData->csRegStatus;
@@ -1808,7 +1808,7 @@ CellularError_t Cellular_CommonGetRegisteredNetwork( CellularHandle_t cellularHa
18081808
}
18091809
else
18101810
{
1811-
memset( pOperatorInfo, 0, sizeof( cellularOperatorInfo_t ) );
1811+
( void ) memset( pOperatorInfo, 0, sizeof( cellularOperatorInfo_t ) );
18121812
cellularStatus = atcmdUpdateMccMnc( pContext, pOperatorInfo );
18131813
}
18141814

@@ -2080,7 +2080,7 @@ void _Cellular_DestroyAtDataMutex( CellularContext_t * pContext )
20802080
{
20812081
configASSERT( pContext != NULL );
20822082

2083-
PlatformMutex_Destroy( &pContext->libAtDataMutex );
2083+
PlatformMutex_Destroy( &( pContext->libAtDataMutex ) );
20842084
}
20852085

20862086
/*-----------------------------------------------------------*/
@@ -2091,7 +2091,7 @@ bool _Cellular_CreateAtDataMutex( CellularContext_t * pContext )
20912091

20922092
configASSERT( pContext != NULL );
20932093

2094-
status = PlatformMutex_Create( &pContext->libAtDataMutex, false );
2094+
status = PlatformMutex_Create( &( pContext->libAtDataMutex ), false );
20952095

20962096
return status;
20972097
}
@@ -2102,7 +2102,7 @@ void _Cellular_LockAtDataMutex( CellularContext_t * pContext )
21022102
{
21032103
configASSERT( pContext != NULL );
21042104

2105-
PlatformMutex_Lock( &pContext->libAtDataMutex );
2105+
PlatformMutex_Lock( &( pContext->libAtDataMutex ) );
21062106
}
21072107

21082108
/*-----------------------------------------------------------*/
@@ -2111,7 +2111,7 @@ void _Cellular_UnlockAtDataMutex( CellularContext_t * pContext )
21112111
{
21122112
configASSERT( pContext != NULL );
21132113

2114-
PlatformMutex_Unlock( &pContext->libAtDataMutex );
2114+
PlatformMutex_Unlock( &( pContext->libAtDataMutex ) );
21152115
}
21162116

21172117
/*-----------------------------------------------------------*/
@@ -2125,7 +2125,7 @@ void _Cellular_InitAtData( CellularContext_t * pContext,
21252125

21262126
configASSERT( pContext != NULL );
21272127

2128-
pLibAtData = &pContext->libAtData;
2128+
pLibAtData = &( pContext->libAtData );
21292129

21302130
if( mode == 0u )
21312131
{
@@ -2667,14 +2667,7 @@ CellularError_t Cellular_CommonGetSimCardLockStatus( CellularHandle_t cellularHa
26672667
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
26682668
CellularError_t cellularStatus = CELLULAR_SUCCESS;
26692669
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
2670-
CellularAtReq_t atReqGetSimLockStatus = { 0 };
2671-
2672-
atReqGetSimLockStatus.pAtCmd = "AT+CPIN?";
2673-
atReqGetSimLockStatus.atCmdType = CELLULAR_AT_WITH_PREFIX;
2674-
atReqGetSimLockStatus.pAtRspPrefix = "+CPIN";
2675-
atReqGetSimLockStatus.respCallback = _Cellular_RecvFuncGetSimLockStatus;
2676-
atReqGetSimLockStatus.pData = NULL;
2677-
atReqGetSimLockStatus.dataLen = 0;
2670+
CellularAtReq_t atReqGetSimLockStatus;
26782671

26792672
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
26802673
cellularStatus = _Cellular_CheckLibraryStatus( pContext );
@@ -2693,7 +2686,11 @@ CellularError_t Cellular_CommonGetSimCardLockStatus( CellularHandle_t cellularHa
26932686
/* Initialize the sim state and the sim lock state. */
26942687
pSimCardStatus->simCardLockState = CELLULAR_SIM_CARD_LOCK_UNKNOWN;
26952688

2696-
atReqGetSimLockStatus.pData = &pSimCardStatus->simCardLockState;
2689+
atReqGetSimLockStatus.pAtCmd = "AT+CPIN?";
2690+
atReqGetSimLockStatus.atCmdType = CELLULAR_AT_WITH_PREFIX;
2691+
atReqGetSimLockStatus.pAtRspPrefix = "+CPIN";
2692+
atReqGetSimLockStatus.respCallback = _Cellular_RecvFuncGetSimLockStatus;
2693+
atReqGetSimLockStatus.pData = &( pSimCardStatus->simCardLockState );
26972694
atReqGetSimLockStatus.dataLen = ( uint16_t ) sizeof( CellularSimCardLockState_t );
26982695

26992696
pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atReqGetSimLockStatus );
@@ -2740,7 +2737,7 @@ CellularError_t Cellular_CommonGetSimCardInfo( CellularHandle_t cellularHandle,
27402737
atReqGetHplmn.atCmdType = CELLULAR_AT_WITH_PREFIX;
27412738
atReqGetHplmn.pAtRspPrefix = "+CRSM";
27422739
atReqGetHplmn.respCallback = _Cellular_RecvFuncGetHplmn;
2743-
atReqGetHplmn.pData = &pSimCardInfo->plmn;
2740+
atReqGetHplmn.pData = &( pSimCardInfo->plmn );
27442741
atReqGetHplmn.dataLen = ( uint16_t ) sizeof( CellularPlmnInfo_t );
27452742

27462743
/* pContext is checked in _Cellular_CheckLibraryStatus function. */
@@ -2856,13 +2853,13 @@ CellularError_t Cellular_CommonSetPsmSettings( CellularHandle_t cellularHandle,
28562853
/* coverity[misra_c_2012_rule_21_6_violation]. */
28572854
( void ) snprintf( cmdBuf, CELLULAR_AT_CMD_MAX_SIZE, "AT+CPSMS=%d,", pPsmSettings->mode );
28582855
cmdBufLen = ( uint32_t ) strlen( cmdBuf );
2859-
cmdBufLen = cmdBufLen + appendBinaryPattern( &cmdBuf[ cmdBufLen ], ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
2856+
cmdBufLen = cmdBufLen + appendBinaryPattern( &( cmdBuf[ cmdBufLen ] ), ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
28602857
pPsmSettings->periodicRauValue, false );
2861-
cmdBufLen = cmdBufLen + appendBinaryPattern( &cmdBuf[ cmdBufLen ], ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
2858+
cmdBufLen = cmdBufLen + appendBinaryPattern( &( cmdBuf[ cmdBufLen ] ), ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
28622859
pPsmSettings->gprsReadyTimer, false );
2863-
cmdBufLen = cmdBufLen + appendBinaryPattern( &cmdBuf[ cmdBufLen ], ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
2860+
cmdBufLen = cmdBufLen + appendBinaryPattern( &( cmdBuf[ cmdBufLen ] ), ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
28642861
pPsmSettings->periodicTauValue, false );
2865-
( void ) appendBinaryPattern( &cmdBuf[ cmdBufLen ], ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
2862+
( void ) appendBinaryPattern( &( cmdBuf[ cmdBufLen ] ), ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
28662863
pPsmSettings->activeTimeValue, true );
28672864

28682865
LogDebug( ( "PSM setting: %s ", cmdBuf ) );
@@ -2919,19 +2916,19 @@ static CellularATError_t parseGetPsmToken( char * pToken,
29192916
break;
29202917

29212918
case CPSMS_POS_RAU:
2922-
atCoreStatus = parseT3412TimerValue( pToken, &pPsmSettings->periodicRauValue );
2919+
atCoreStatus = parseT3412TimerValue( pToken, &( pPsmSettings->periodicRauValue ) );
29232920
break;
29242921

29252922
case CPSMS_POS_RDY_TIMER:
2926-
atCoreStatus = parseT3324TimerValue( pToken, &pPsmSettings->gprsReadyTimer );
2923+
atCoreStatus = parseT3324TimerValue( pToken, &( pPsmSettings->gprsReadyTimer ) );
29272924
break;
29282925

29292926
case CPSMS_POS_TAU:
2930-
atCoreStatus = parseT3412TimerValue( pToken, &pPsmSettings->periodicTauValue );
2927+
atCoreStatus = parseT3412TimerValue( pToken, &( pPsmSettings->periodicTauValue ) );
29312928
break;
29322929

29332930
case CPSMS_POS_ACTIVE_TIME:
2934-
atCoreStatus = parseT3324TimerValue( pToken, &pPsmSettings->activeTimeValue );
2931+
atCoreStatus = parseT3324TimerValue( pToken, &( pPsmSettings->activeTimeValue ) );
29352932
break;
29362933

29372934
default:

source/cellular_3gpp_urc_handler.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ CellularPktStatus_t _Cellular_ParseRegStatus( CellularContext_t * pContext,
559559
}
560560
else
561561
{
562-
pLibAtData = &pContext->libAtData;
562+
pLibAtData = &( pContext->libAtData );
563563

564564
if( isUrc == true )
565565
{

source/cellular_at_core.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ CellularATError_t Cellular_ATRemoveTrailingWhiteSpaces( char * pString )
330330
* when the string length is greater than 2. */
331331
if( stringLen > 2U )
332332
{
333-
p = &pString[ stringLen ];
333+
p = &( pString[ stringLen ] );
334334

335335
do
336336
{
@@ -571,11 +571,11 @@ CellularATError_t Cellular_ATGetSpecificNextTok( char ** ppString,
571571

572572
if( ( tokStrLen < dataStrlen ) && ( ( *ppString )[ tokStrLen + 1U ] != '\0' ) )
573573
{
574-
*ppString = &tok[ strlen( tok ) + 1U ];
574+
*ppString = &( tok[ strlen( tok ) + 1U ] );
575575
}
576576
else
577577
{
578-
*ppString = &tok[ strlen( tok ) ];
578+
*ppString = &( tok[ strlen( tok ) ] );
579579
}
580580

581581
*ppTokOutput = tok;
@@ -665,7 +665,7 @@ CellularATError_t Cellular_ATHexStrToHex( const char * pString,
665665
( pHexData )[ i ] = firstNibble | secondNibble;
666666
}
667667

668-
p = &p[ 2 ];
668+
p = &( p[ 2 ] );
669669
}
670670
}
671671

0 commit comments

Comments
 (0)