Skip to content

Commit

Permalink
Fix MISRA C 2012 deviations (FreeRTOS#165)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
chinglee-iot and Ubuntu authored Mar 14, 2024
1 parent df553bd commit 71d6f60
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 242 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
cmake -S test -B build/ \
-G "Unix Makefiles" \
-DCMAKE_BUILD_TYPE=Debug \
-DUNITTEST=ON \
-DBUILD_CLONE_SUBMODULES=ON \
-DCMAKE_C_FLAGS='--coverage -Wall -Wextra -Werror -DNDEBUG'
Expand Down
8 changes: 4 additions & 4 deletions docs/doxygen/include/size_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</tr>
<tr>
<td>cellular_3gpp_api.c</td>
<td><center>6.5K</center></td>
<td><center>6.4K</center></td>
<td><center>5.9K</center></td>
</tr>
<tr>
Expand Down Expand Up @@ -39,12 +39,12 @@
</tr>
<tr>
<td>cellular_pktio.c</td>
<td><center>2.2K</center></td>
<td><center>1.9K</center></td>
<td><center>2.3K</center></td>
<td><center>2.0K</center></td>
</tr>
<tr>
<td><b>Total estimates</b></td>
<td><b><center>15.1K</center></b></td>
<td><b><center>13.7K</center></b></td>
<td><b><center>13.8K</center></b></td>
</tr>
</table>
53 changes: 25 additions & 28 deletions source/cellular_3gpp_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ static bool _parseCopsNetworkNameToken( const char * pToken,
{
( void ) strncpy( pOperatorInfo->plmnInfo.mcc, pToken, CELLULAR_MCC_MAX_SIZE );
pOperatorInfo->plmnInfo.mcc[ CELLULAR_MCC_MAX_SIZE ] = '\0';
( void ) strncpy( pOperatorInfo->plmnInfo.mnc, &pToken[ CELLULAR_MCC_MAX_SIZE ],
( void ) strncpy( pOperatorInfo->plmnInfo.mnc, &( pToken[ CELLULAR_MCC_MAX_SIZE ] ),
( uint32_t ) ( mccMncLen - CELLULAR_MCC_MAX_SIZE + 1u ) );
pOperatorInfo->plmnInfo.mnc[ CELLULAR_MNC_MAX_SIZE ] = '\0';
}
Expand Down Expand Up @@ -1419,8 +1419,8 @@ static CellularError_t atcmdUpdateMccMnc( CellularContext_t * pContext,
CellularAtReq_t atCopsRequest = { 0 };

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

if( pktStatus == CELLULAR_PKT_STATUS_OK )
Expand Down Expand Up @@ -1482,7 +1482,7 @@ static CellularError_t atcmdQueryRegStatus( CellularContext_t * pContext,
/* Get the service status from lib AT data. */
if( cellularStatus == CELLULAR_SUCCESS )
{
pLibAtData = &pContext->libAtData;
pLibAtData = &( pContext->libAtData );
_Cellular_LockAtDataMutex( pContext );
pServiceStatus->rat = pLibAtData->rat;
pServiceStatus->csRegistrationStatus = pLibAtData->csRegStatus;
Expand Down Expand Up @@ -1808,7 +1808,7 @@ CellularError_t Cellular_CommonGetRegisteredNetwork( CellularHandle_t cellularHa
}
else
{
memset( pOperatorInfo, 0, sizeof( cellularOperatorInfo_t ) );
( void ) memset( pOperatorInfo, 0, sizeof( cellularOperatorInfo_t ) );
cellularStatus = atcmdUpdateMccMnc( pContext, pOperatorInfo );
}

Expand Down Expand Up @@ -2080,7 +2080,7 @@ void _Cellular_DestroyAtDataMutex( CellularContext_t * pContext )
{
configASSERT( pContext != NULL );

PlatformMutex_Destroy( &pContext->libAtDataMutex );
PlatformMutex_Destroy( &( pContext->libAtDataMutex ) );
}

/*-----------------------------------------------------------*/
Expand All @@ -2091,7 +2091,7 @@ bool _Cellular_CreateAtDataMutex( CellularContext_t * pContext )

configASSERT( pContext != NULL );

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

return status;
}
Expand All @@ -2102,7 +2102,7 @@ void _Cellular_LockAtDataMutex( CellularContext_t * pContext )
{
configASSERT( pContext != NULL );

PlatformMutex_Lock( &pContext->libAtDataMutex );
PlatformMutex_Lock( &( pContext->libAtDataMutex ) );
}

/*-----------------------------------------------------------*/
Expand All @@ -2111,7 +2111,7 @@ void _Cellular_UnlockAtDataMutex( CellularContext_t * pContext )
{
configASSERT( pContext != NULL );

PlatformMutex_Unlock( &pContext->libAtDataMutex );
PlatformMutex_Unlock( &( pContext->libAtDataMutex ) );
}

/*-----------------------------------------------------------*/
Expand All @@ -2125,7 +2125,7 @@ void _Cellular_InitAtData( CellularContext_t * pContext,

configASSERT( pContext != NULL );

pLibAtData = &pContext->libAtData;
pLibAtData = &( pContext->libAtData );

if( mode == 0u )
{
Expand Down Expand Up @@ -2667,14 +2667,7 @@ CellularError_t Cellular_CommonGetSimCardLockStatus( CellularHandle_t cellularHa
CellularContext_t * pContext = ( CellularContext_t * ) cellularHandle;
CellularError_t cellularStatus = CELLULAR_SUCCESS;
CellularPktStatus_t pktStatus = CELLULAR_PKT_STATUS_OK;
CellularAtReq_t atReqGetSimLockStatus = { 0 };

atReqGetSimLockStatus.pAtCmd = "AT+CPIN?";
atReqGetSimLockStatus.atCmdType = CELLULAR_AT_WITH_PREFIX;
atReqGetSimLockStatus.pAtRspPrefix = "+CPIN";
atReqGetSimLockStatus.respCallback = _Cellular_RecvFuncGetSimLockStatus;
atReqGetSimLockStatus.pData = NULL;
atReqGetSimLockStatus.dataLen = 0;
CellularAtReq_t atReqGetSimLockStatus;

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

atReqGetSimLockStatus.pData = &pSimCardStatus->simCardLockState;
atReqGetSimLockStatus.pAtCmd = "AT+CPIN?";
atReqGetSimLockStatus.atCmdType = CELLULAR_AT_WITH_PREFIX;
atReqGetSimLockStatus.pAtRspPrefix = "+CPIN";
atReqGetSimLockStatus.respCallback = _Cellular_RecvFuncGetSimLockStatus;
atReqGetSimLockStatus.pData = &( pSimCardStatus->simCardLockState );
atReqGetSimLockStatus.dataLen = ( uint16_t ) sizeof( CellularSimCardLockState_t );

pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atReqGetSimLockStatus );
Expand Down Expand Up @@ -2740,7 +2737,7 @@ CellularError_t Cellular_CommonGetSimCardInfo( CellularHandle_t cellularHandle,
atReqGetHplmn.atCmdType = CELLULAR_AT_WITH_PREFIX;
atReqGetHplmn.pAtRspPrefix = "+CRSM";
atReqGetHplmn.respCallback = _Cellular_RecvFuncGetHplmn;
atReqGetHplmn.pData = &pSimCardInfo->plmn;
atReqGetHplmn.pData = &( pSimCardInfo->plmn );
atReqGetHplmn.dataLen = ( uint16_t ) sizeof( CellularPlmnInfo_t );

/* pContext is checked in _Cellular_CheckLibraryStatus function. */
Expand Down Expand Up @@ -2856,13 +2853,13 @@ CellularError_t Cellular_CommonSetPsmSettings( CellularHandle_t cellularHandle,
/* coverity[misra_c_2012_rule_21_6_violation]. */
( void ) snprintf( cmdBuf, CELLULAR_AT_CMD_MAX_SIZE, "AT+CPSMS=%d,", pPsmSettings->mode );
cmdBufLen = ( uint32_t ) strlen( cmdBuf );
cmdBufLen = cmdBufLen + appendBinaryPattern( &cmdBuf[ cmdBufLen ], ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
cmdBufLen = cmdBufLen + appendBinaryPattern( &( cmdBuf[ cmdBufLen ] ), ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
pPsmSettings->periodicRauValue, false );
cmdBufLen = cmdBufLen + appendBinaryPattern( &cmdBuf[ cmdBufLen ], ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
cmdBufLen = cmdBufLen + appendBinaryPattern( &( cmdBuf[ cmdBufLen ] ), ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
pPsmSettings->gprsReadyTimer, false );
cmdBufLen = cmdBufLen + appendBinaryPattern( &cmdBuf[ cmdBufLen ], ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
cmdBufLen = cmdBufLen + appendBinaryPattern( &( cmdBuf[ cmdBufLen ] ), ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
pPsmSettings->periodicTauValue, false );
( void ) appendBinaryPattern( &cmdBuf[ cmdBufLen ], ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
( void ) appendBinaryPattern( &( cmdBuf[ cmdBufLen ] ), ( CELLULAR_AT_CMD_MAX_SIZE - cmdBufLen ),
pPsmSettings->activeTimeValue, true );

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

case CPSMS_POS_RAU:
atCoreStatus = parseT3412TimerValue( pToken, &pPsmSettings->periodicRauValue );
atCoreStatus = parseT3412TimerValue( pToken, &( pPsmSettings->periodicRauValue ) );
break;

case CPSMS_POS_RDY_TIMER:
atCoreStatus = parseT3324TimerValue( pToken, &pPsmSettings->gprsReadyTimer );
atCoreStatus = parseT3324TimerValue( pToken, &( pPsmSettings->gprsReadyTimer ) );
break;

case CPSMS_POS_TAU:
atCoreStatus = parseT3412TimerValue( pToken, &pPsmSettings->periodicTauValue );
atCoreStatus = parseT3412TimerValue( pToken, &( pPsmSettings->periodicTauValue ) );
break;

case CPSMS_POS_ACTIVE_TIME:
atCoreStatus = parseT3324TimerValue( pToken, &pPsmSettings->activeTimeValue );
atCoreStatus = parseT3324TimerValue( pToken, &( pPsmSettings->activeTimeValue ) );
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion source/cellular_3gpp_urc_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ CellularPktStatus_t _Cellular_ParseRegStatus( CellularContext_t * pContext,
}
else
{
pLibAtData = &pContext->libAtData;
pLibAtData = &( pContext->libAtData );

if( isUrc == true )
{
Expand Down
8 changes: 4 additions & 4 deletions source/cellular_at_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ CellularATError_t Cellular_ATRemoveTrailingWhiteSpaces( char * pString )
* when the string length is greater than 2. */
if( stringLen > 2U )
{
p = &pString[ stringLen ];
p = &( pString[ stringLen ] );

do
{
Expand Down Expand Up @@ -571,11 +571,11 @@ CellularATError_t Cellular_ATGetSpecificNextTok( char ** ppString,

if( ( tokStrLen < dataStrlen ) && ( ( *ppString )[ tokStrLen + 1U ] != '\0' ) )
{
*ppString = &tok[ strlen( tok ) + 1U ];
*ppString = &( tok[ strlen( tok ) + 1U ] );
}
else
{
*ppString = &tok[ strlen( tok ) ];
*ppString = &( tok[ strlen( tok ) ] );
}

*ppTokOutput = tok;
Expand Down Expand Up @@ -665,7 +665,7 @@ CellularATError_t Cellular_ATHexStrToHex( const char * pString,
( pHexData )[ i ] = firstNibble | secondNibble;
}

p = &p[ 2 ];
p = &( p[ 2 ] );
}
}

Expand Down
Loading

0 comments on commit 71d6f60

Please sign in to comment.