Skip to content

Commit d6d3323

Browse files
committed
Fix MISRA deviations
* Suppress MISRA dir 4.6 to return int to comply with search function prototype * Fix MISRA rule 15.4 to use single break in loop * Fix MISRA rule 17.12 to use & to obtain the functoin address * Update coverity README.md to add compile option
1 parent 763dfa0 commit d6d3323

7 files changed

+47
-37
lines changed

MISRA.md

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ _Ref 4.6.1_
2929
We do not have control over these functions so we are suppressing these
3030
violations.
3131

32+
_Ref 4.6.2_
33+
34+
- MISRA C-2012 Directive 4.6 warns against using types that do not contain size
35+
and sign information. However, in this case, the search function requires a
36+
comparison function pointer that returns a value of type int. To maintain
37+
compatibility with the search function's expected prototype, the comparison
38+
function must return an int type value despite the MISRA guidance.
39+
3240
#### Directive 4.7
3341

3442
_Ref 4.7.1_

source/cellular_3gpp_api.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ static CellularError_t queryNetworkStatus( CellularContext_t * pContext,
867867
atReqGetResult.pAtCmd = pCommand;
868868
atReqGetResult.atCmdType = CELLULAR_AT_MULTI_WITH_PREFIX;
869869
atReqGetResult.pAtRspPrefix = pPrefix;
870-
atReqGetResult.respCallback = _Cellular_RecvFuncGetNetworkReg;
870+
atReqGetResult.respCallback = &_Cellular_RecvFuncGetNetworkReg;
871871
atReqGetResult.pData = &recvRegType;
872872
atReqGetResult.dataLen = ( uint16_t ) sizeof( CellularNetworkRegType_t );
873873

@@ -1429,7 +1429,7 @@ static CellularError_t atcmdUpdateMccMnc( CellularContext_t * pContext,
14291429
atCopsRequest.pAtCmd = "AT+COPS?";
14301430
atCopsRequest.atCmdType = CELLULAR_AT_WITH_PREFIX;
14311431
atCopsRequest.pAtRspPrefix = "+COPS";
1432-
atCopsRequest.respCallback = _Cellular_RecvFuncUpdateMccMnc;
1432+
atCopsRequest.respCallback = &_Cellular_RecvFuncUpdateMccMnc;
14331433
atCopsRequest.pData = pOperatorInfo;
14341434
atCopsRequest.dataLen = ( uint16_t ) sizeof( cellularOperatorInfo_t );
14351435
pktStatus = _Cellular_AtcmdRequestWithCallback( pContext, atCopsRequest );
@@ -1638,7 +1638,7 @@ CellularError_t Cellular_CommonGetEidrxSettings( CellularHandle_t cellularHandle
16381638
atReqGetEidrx.pAtCmd = "AT+CEDRXS?";
16391639
atReqGetEidrx.atCmdType = CELLULAR_AT_MULTI_WITH_PREFIX;
16401640
atReqGetEidrx.pAtRspPrefix = "+CEDRXS";
1641-
atReqGetEidrx.respCallback = _Cellular_RecvFuncGetEidrxSettings;
1641+
atReqGetEidrx.respCallback = &_Cellular_RecvFuncGetEidrxSettings;
16421642
atReqGetEidrx.pData = pEidrxSettingsList;
16431643
atReqGetEidrx.dataLen = CELLULAR_EDRX_LIST_MAX_SIZE;
16441644

@@ -1898,7 +1898,7 @@ CellularError_t Cellular_CommonGetNetworkTime( CellularHandle_t cellularHandle,
18981898
atReqGetNetworkTime.pAtCmd = "AT+CCLK?";
18991899
atReqGetNetworkTime.atCmdType = CELLULAR_AT_WITH_PREFIX;
19001900
atReqGetNetworkTime.pAtRspPrefix = "+CCLK";
1901-
atReqGetNetworkTime.respCallback = _Cellular_RecvFuncGetNetworkTime;
1901+
atReqGetNetworkTime.respCallback = &_Cellular_RecvFuncGetNetworkTime;
19021902
atReqGetNetworkTime.pData = pNetworkTime;
19031903
atReqGetNetworkTime.dataLen = ( uint16_t ) sizeof( CellularTime_t );
19041904

@@ -1943,28 +1943,28 @@ CellularError_t Cellular_CommonGetModemInfo( CellularHandle_t cellularHandle,
19431943
atReqGetFirmwareVersion.pAtCmd = "AT+CGMR";
19441944
atReqGetFirmwareVersion.atCmdType = CELLULAR_AT_WO_PREFIX;
19451945
atReqGetFirmwareVersion.pAtRspPrefix = NULL;
1946-
atReqGetFirmwareVersion.respCallback = _Cellular_RecvFuncGetFirmwareVersion;
1946+
atReqGetFirmwareVersion.respCallback = &_Cellular_RecvFuncGetFirmwareVersion;
19471947
atReqGetFirmwareVersion.pData = pModemInfo->firmwareVersion;
19481948
atReqGetFirmwareVersion.dataLen = CELLULAR_FW_VERSION_MAX_SIZE + 1U;
19491949

19501950
atReqGetImei.pAtCmd = "AT+CGSN";
19511951
atReqGetImei.atCmdType = CELLULAR_AT_WO_PREFIX;
19521952
atReqGetImei.pAtRspPrefix = NULL;
1953-
atReqGetImei.respCallback = _Cellular_RecvFuncGetImei;
1953+
atReqGetImei.respCallback = &_Cellular_RecvFuncGetImei;
19541954
atReqGetImei.pData = pModemInfo->imei;
19551955
atReqGetImei.dataLen = CELLULAR_IMEI_MAX_SIZE + 1U;
19561956

19571957
atReqGetModelId.pAtCmd = "AT+CGMM";
19581958
atReqGetModelId.atCmdType = CELLULAR_AT_WO_PREFIX;
19591959
atReqGetModelId.pAtRspPrefix = NULL;
1960-
atReqGetModelId.respCallback = _Cellular_RecvFuncGetModelId;
1960+
atReqGetModelId.respCallback = &_Cellular_RecvFuncGetModelId;
19611961
atReqGetModelId.pData = pModemInfo->modelId;
19621962
atReqGetModelId.dataLen = CELLULAR_MODEL_ID_MAX_SIZE + 1U;
19631963

19641964
atReqGetManufactureId.pAtCmd = "AT+CGMI";
19651965
atReqGetManufactureId.atCmdType = CELLULAR_AT_WO_PREFIX;
19661966
atReqGetManufactureId.pAtRspPrefix = NULL;
1967-
atReqGetManufactureId.respCallback = _Cellular_RecvFuncGetManufactureId;
1967+
atReqGetManufactureId.respCallback = &_Cellular_RecvFuncGetManufactureId;
19681968
atReqGetManufactureId.pData = pModemInfo->manufactureId;
19691969
atReqGetManufactureId.dataLen = CELLULAR_MANUFACTURE_ID_MAX_SIZE + 1U;
19701970

@@ -2031,7 +2031,7 @@ CellularError_t Cellular_CommonGetIPAddress( CellularHandle_t cellularHandle,
20312031
atReqGetIp.pAtCmd = cmdBuf;
20322032
atReqGetIp.atCmdType = CELLULAR_AT_WITH_PREFIX;
20332033
atReqGetIp.pAtRspPrefix = "+CGPADDR";
2034-
atReqGetIp.respCallback = _Cellular_RecvFuncIpAddress;
2034+
atReqGetIp.respCallback = &_Cellular_RecvFuncIpAddress;
20352035
atReqGetIp.pData = pBuffer;
20362036
atReqGetIp.dataLen = ( uint16_t ) bufferLength;
20372037

@@ -2689,7 +2689,7 @@ CellularError_t Cellular_CommonGetSimCardLockStatus( CellularHandle_t cellularHa
26892689
atReqGetSimLockStatus.pAtCmd = "AT+CPIN?";
26902690
atReqGetSimLockStatus.atCmdType = CELLULAR_AT_WITH_PREFIX;
26912691
atReqGetSimLockStatus.pAtRspPrefix = "+CPIN";
2692-
atReqGetSimLockStatus.respCallback = _Cellular_RecvFuncGetSimLockStatus;
2692+
atReqGetSimLockStatus.respCallback = &_Cellular_RecvFuncGetSimLockStatus;
26932693
atReqGetSimLockStatus.pData = &( pSimCardStatus->simCardLockState );
26942694
atReqGetSimLockStatus.dataLen = ( uint16_t ) sizeof( CellularSimCardLockState_t );
26952695

@@ -2721,22 +2721,22 @@ CellularError_t Cellular_CommonGetSimCardInfo( CellularHandle_t cellularHandle,
27212721
atReqGetIccid.pAtCmd = "AT+CCID";
27222722
atReqGetIccid.atCmdType = CELLULAR_AT_WITH_PREFIX;
27232723
atReqGetIccid.pAtRspPrefix = "+CCID";
2724-
atReqGetIccid.respCallback = _Cellular_RecvFuncGetIccid;
2724+
atReqGetIccid.respCallback = &_Cellular_RecvFuncGetIccid;
27252725
atReqGetIccid.pData = pSimCardInfo->iccid;
27262726
atReqGetIccid.dataLen = CELLULAR_ICCID_MAX_SIZE + 1U;
27272727
#endif
27282728

27292729
atReqGetImsi.pAtCmd = "AT+CIMI";
27302730
atReqGetImsi.atCmdType = CELLULAR_AT_WO_PREFIX;
27312731
atReqGetImsi.pAtRspPrefix = NULL;
2732-
atReqGetImsi.respCallback = _Cellular_RecvFuncGetImsi;
2732+
atReqGetImsi.respCallback = &_Cellular_RecvFuncGetImsi;
27332733
atReqGetImsi.pData = pSimCardInfo->imsi;
27342734
atReqGetImsi.dataLen = CELLULAR_IMSI_MAX_SIZE + 1U;
27352735

27362736
atReqGetHplmn.pAtCmd = "AT+CRSM=176,28514,0,0,0"; /* READ BINARY command. HPLMN Selector with Access Technology( 6F62 ). */
27372737
atReqGetHplmn.atCmdType = CELLULAR_AT_WITH_PREFIX;
27382738
atReqGetHplmn.pAtRspPrefix = "+CRSM";
2739-
atReqGetHplmn.respCallback = _Cellular_RecvFuncGetHplmn;
2739+
atReqGetHplmn.respCallback = &_Cellular_RecvFuncGetHplmn;
27402740
atReqGetHplmn.pData = &( pSimCardInfo->plmn );
27412741
atReqGetHplmn.dataLen = ( uint16_t ) sizeof( CellularPlmnInfo_t );
27422742

@@ -3025,7 +3025,7 @@ CellularError_t Cellular_CommonGetPsmSettings( CellularHandle_t cellularHandle,
30253025
atReqGetPsm.pAtCmd = "AT+CPSMS?";
30263026
atReqGetPsm.atCmdType = CELLULAR_AT_WITH_PREFIX;
30273027
atReqGetPsm.pAtRspPrefix = "+CPSMS";
3028-
atReqGetPsm.respCallback = _Cellular_RecvFuncGetPsmSettings;
3028+
atReqGetPsm.respCallback = &_Cellular_RecvFuncGetPsmSettings;
30293029
atReqGetPsm.pData = pPsmSettings;
30303030
atReqGetPsm.dataLen = ( uint16_t ) sizeof( CellularPsmSettings_t );
30313031

source/cellular_3gpp_urc_handler.c

+9-13
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static CellularPktStatus_t _parseRejectCauseInRegStatus( CellularNetworkRegType_
8888
static CellularPktStatus_t _parseRoutingAreaCodeInRegStatus( const char * pToken,
8989
cellularAtData_t * pLibAtData );
9090
static CellularPktStatus_t _regStatusSwitchParsingFunc( CellularContext_t * pContext,
91-
uint8_t i,
91+
uint8_t regPos,
9292
CellularNetworkRegType_t regType,
9393
const char * pToken,
9494
cellularAtData_t * pLibAtData );
@@ -746,15 +746,15 @@ CellularPktStatus_t _Cellular_ParseRegStatus( CellularContext_t * pContext,
746746
switch( regType )
747747
{
748748
case CELLULAR_REG_TYPE_CREG:
749-
pRegStatusParsingFunc = _regStatusSwitchParsingFuncCreg;
749+
pRegStatusParsingFunc = &_regStatusSwitchParsingFuncCreg;
750750
break;
751751

752752
case CELLULAR_REG_TYPE_CGREG:
753-
pRegStatusParsingFunc = _regStatusSwitchParsingFuncCgreg;
753+
pRegStatusParsingFunc = &_regStatusSwitchParsingFuncCgreg;
754754
break;
755755

756756
case CELLULAR_REG_TYPE_CEREG:
757-
pRegStatusParsingFunc = _regStatusSwitchParsingFuncCereg;
757+
pRegStatusParsingFunc = &_regStatusSwitchParsingFuncCereg;
758758
break;
759759

760760
default:
@@ -806,16 +806,12 @@ CellularPktStatus_t _Cellular_ParseRegStatus( CellularContext_t * pContext,
806806
while( pToken != NULL )
807807
{
808808
i++;
809-
809+
810810
packetStatus = pRegStatusParsingFunc( pContext, i, pToken, pLibAtData );
811-
812-
if( packetStatus != CELLULAR_PKT_STATUS_OK )
813-
{
814-
break;
815-
}
816-
817-
/* Getting next token to parse. */
818-
if( Cellular_ATGetNextTok( &pRegStr, &pToken ) != CELLULAR_AT_SUCCESS )
811+
812+
/* Continue only if status is OK and we can get the next token */
813+
if( (packetStatus != CELLULAR_PKT_STATUS_OK) ||
814+
(Cellular_ATGetNextTok( &pRegStr, &pToken ) != CELLULAR_AT_SUCCESS) )
819815
{
820816
break;
821817
}

source/cellular_common.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,12 @@ static CellularError_t libOpen( CellularContext_t * pContext )
188188
_Cellular_LockAtDataMutex( pContext );
189189
_Cellular_InitAtData( pContext, 0 );
190190
_Cellular_UnlockAtDataMutex( pContext );
191-
_Cellular_SetShutdownCallback( pContext, _shutdownCallback );
191+
_Cellular_SetShutdownCallback( pContext, &_shutdownCallback );
192192
pktStatus = _Cellular_PktHandlerInit( pContext );
193193

194194
if( pktStatus == CELLULAR_PKT_STATUS_OK )
195195
{
196-
pktStatus = _Cellular_PktioInit( pContext, _Cellular_HandlePacket );
196+
pktStatus = _Cellular_PktioInit( pContext, &_Cellular_HandlePacket );
197197

198198
if( pktStatus != CELLULAR_PKT_STATUS_OK )
199199
{

source/cellular_pkthandler.c

+10-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static CellularPktStatus_t _Cellular_DataSendWithTimeoutDelayRaw( CellularContex
7171
uint32_t timeoutMs );
7272
static void _Cellular_PktHandlerAcquirePktRequestMutex( CellularContext_t * pContext );
7373
static void _Cellular_PktHandlerReleasePktRequestMutex( CellularContext_t * pContext );
74-
static int32_t _searchCompareFunc( const void * pInputToken,
74+
static int _searchCompareFunc( const void * pInputToken,
7575
const void * pBase );
7676
static int32_t _sortCompareFunc( const void * pElem1Ptr,
7777
const void * pElem2Ptr );
@@ -360,10 +360,16 @@ static void _Cellular_PktHandlerReleasePktRequestMutex( CellularContext_t * pCon
360360

361361
/*-----------------------------------------------------------*/
362362

363-
static int32_t _searchCompareFunc( const void * pInputToken,
363+
/* MISRA Ref 4.6. [Basic numerical type] */
364+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#directive-46 */
365+
/* coverity[misra_c_2012_directive_4_6_violation] */
366+
static int _searchCompareFunc( const void * pInputToken,
364367
const void * pBase )
365368
{
366-
int32_t compareValue = 0;
369+
/* MISRA Ref 4.6. [Basic numerical type] */
370+
/* More details at: https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/MISRA.md#directive-46 */
371+
/* coverity[misra_c_2012_directive_4_6_violation] */
372+
int compareValue = 0;
367373
const char * pToken = ( const char * ) pInputToken;
368374
const CellularAtParseTokenMap_t * pBasePtr = ( const CellularAtParseTokenMap_t * ) pBase;
369375
uint32_t tokenLen = ( uint32_t ) strlen( pInputToken );
@@ -441,7 +447,7 @@ static CellularPktStatus_t _atParseGetHandler( CellularContext_t * pContext,
441447
( const void * ) pTokenMap,
442448
tokenMapSize,
443449
sizeof( CellularAtParseTokenMap_t ),
444-
_searchCompareFunc );
450+
&_searchCompareFunc );
445451

446452
if( pElementPtr != NULL )
447453
{

source/cellular_pktio.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ static void _pktioReadThread( void * pUserData )
12061206

12071207
/* Open main communication port. */
12081208
if( ( pContext->pCommIntf != NULL ) &&
1209-
( pContext->pCommIntf->open( _Cellular_PktRxCallBack, ( void * ) pContext,
1209+
( pContext->pCommIntf->open( &_Cellular_PktRxCallBack, ( void * ) pContext,
12101210
&( pContext->hPktioCommIntf ) ) == IOT_COMM_INTERFACE_SUCCESS ) )
12111211
{
12121212
/* Send thread started event. */
@@ -1370,7 +1370,7 @@ CellularPktStatus_t _Cellular_PktioInit( CellularContext_t * pContext,
13701370
( ( PlatformEventBits_t ) PKTIO_EVT_MASK_ALL_EVENTS ) );
13711371

13721372
/* Create the Read thread. */
1373-
status = Platform_CreateDetachedThread( _pktioReadThread,
1373+
status = Platform_CreateDetachedThread( &_pktioReadThread,
13741374
( void * ) pContext,
13751375
PLATFORM_THREAD_DEFAULT_PRIORITY,
13761376
PLATFORM_THREAD_DEFAULT_STACK_SIZE );

tools/coverity/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Go to the root directory of the library and run the following commands in termin
3131
~~~
3232
2. Create the build files using CMake in a `build` directory
3333
~~~
34-
cmake -B build -S test
34+
cmake -B build -S test -DCOV_ANALYSIS=ON
3535
~~~
3636
3. Go to the build directory and copy the coverity configuration file
3737
~~~
@@ -62,7 +62,7 @@ Go to the root directory of the library and run the following commands in termin
6262
For your convenience the commands above are below to be copy/pasted into a UNIX command friendly terminal.
6363
~~~
6464
cov-configure --force --compiler cc --comptype gcc;
65-
cmake -B build -S test;
65+
cmake -B build -S test -DCOV_ANALYSIS=ON;
6666
cd build/;
6767
cov-build --emit-complementary-info --dir cov-out make coverity_analysis;
6868
cd cov-out/

0 commit comments

Comments
 (0)