Add more static analysis and MISRA.md
(cherry picked from commit ad337c3e9c4e879721ec432bc9a5d9a84a53c573) # Conflicts: # CANopen.c
This commit is contained in:
parent
8cccf6f379
commit
f7c7f9c104
4 changed files with 159 additions and 25 deletions
|
|
@ -116,7 +116,12 @@ ODR_t OD_writeOriginal(OD_stream_t *stream, const void *buf,
|
|||
return ODR_DATA_LONG;
|
||||
}
|
||||
|
||||
(void)memcpy((void *)dataOrig, (const void *)buf, dataLenToCopy);
|
||||
if (((dataLenToCopy + stream->dataOffset) <= stream->dataLength) && (dataLenToCopy <= count)) {
|
||||
(void)memcpy((void *)dataOrig, (const void *)buf, dataLenToCopy);
|
||||
}
|
||||
else {
|
||||
return ODR_DEV_INCOMPAT;
|
||||
}
|
||||
|
||||
*countWritten = dataLenToCopy;
|
||||
return returnCode;
|
||||
|
|
|
|||
37
301/CO_PDO.c
37
301/CO_PDO.c
|
|
@ -444,16 +444,17 @@ static ODR_t OD_read_PDO_commParam(OD_stream_t *stream, void *buf,
|
|||
******************************************************************************/
|
||||
#if ((CO_CONFIG_PDO) & CO_CONFIG_RPDO_ENABLE) != 0
|
||||
/*
|
||||
* States for RPDO->receiveError indicates received RPDOs with wrong length.
|
||||
* @defgroup CO_PDO_receiveErrors_t States for RPDO->receiveError indicates received RPDOs with wrong length.
|
||||
* @{
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
CO_RPDO_RX_ACK_NO_ERROR = 0, /* No error */
|
||||
CO_RPDO_RX_ACK_ERROR = 1, /* Error is acknowledged */
|
||||
CO_RPDO_RX_ACK = 10, /* Auxiliary value */
|
||||
CO_RPDO_RX_OK = 11, /* Correct RPDO received, not acknowledged */
|
||||
CO_RPDO_RX_SHORT = 12, /* Too short RPDO received, not acknowledged */
|
||||
CO_RPDO_RX_LONG = 13 /* Too long RPDO received, not acknowledged */
|
||||
} CO_PDO_receiveErrors_t;
|
||||
#define CO_RPDO_RX_ACK_NO_ERROR 0U /* No error */
|
||||
#define CO_RPDO_RX_ACK_ERROR 1U /* Error is acknowledged */
|
||||
#define CO_RPDO_RX_ACK 10U /* Auxiliary value */
|
||||
#define CO_RPDO_RX_OK 11U /* Correct RPDO received, not acknowledged */
|
||||
#define CO_RPDO_RX_SHORT 12U /* Too short RPDO received, not acknowledged */
|
||||
#define CO_RPDO_RX_LONG 13U /* Too long RPDO received, not acknowledged */
|
||||
/** @} */ /* CO_PDO_receiveErrors_t */
|
||||
|
||||
/*
|
||||
* Read received message from CAN module.
|
||||
|
|
@ -475,10 +476,10 @@ static void CO_PDO_receive(void *object, void *msg) {
|
|||
if (DLC >= PDO->dataLength) {
|
||||
/* indicate errors in PDO length */
|
||||
if (DLC == PDO->dataLength) {
|
||||
if (err == (uint8_t)CO_RPDO_RX_ACK_ERROR) { err = (uint8_t)(CO_RPDO_RX_OK); }
|
||||
if (err == CO_RPDO_RX_ACK_ERROR) { err = CO_RPDO_RX_OK; }
|
||||
}
|
||||
else {
|
||||
if (err == (uint8_t)CO_RPDO_RX_ACK_NO_ERROR) { err = (uint8_t)(CO_RPDO_RX_LONG); }
|
||||
if (err == CO_RPDO_RX_ACK_NO_ERROR) { err = CO_RPDO_RX_LONG; }
|
||||
}
|
||||
|
||||
/* Determine, to which of the two rx buffers copy the message. */
|
||||
|
|
@ -492,7 +493,7 @@ static void CO_PDO_receive(void *object, void *msg) {
|
|||
#endif
|
||||
|
||||
/* copy data into appropriate buffer and set 'new message' flag */
|
||||
(void)memcpy(RPDO->CANrxData[bufNo], data,sizeof(RPDO->CANrxData[bufNo]));
|
||||
(void)memcpy(RPDO->CANrxData[bufNo], data, CO_PDO_MAX_SIZE);
|
||||
CO_FLAG_SET(RPDO->CANrxNew[bufNo]);
|
||||
|
||||
#if ((CO_CONFIG_PDO) & CO_CONFIG_FLAG_CALLBACK_PRE) != 0
|
||||
|
|
@ -503,8 +504,8 @@ static void CO_PDO_receive(void *object, void *msg) {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
else if (err == (uint8_t)CO_RPDO_RX_ACK_NO_ERROR) {
|
||||
err = (uint8_t)(CO_RPDO_RX_SHORT);
|
||||
else if (err == CO_RPDO_RX_ACK_NO_ERROR) {
|
||||
err = CO_RPDO_RX_SHORT;
|
||||
}
|
||||
else { /* MISRA C 2004 14.10 */ }
|
||||
}
|
||||
|
|
@ -806,14 +807,14 @@ void CO_RPDO_process(CO_RPDO_t *RPDO,
|
|||
#endif
|
||||
) {
|
||||
/* Verify errors in length of received RPDO CAN message */
|
||||
if (RPDO->receiveError > (uint8_t)CO_RPDO_RX_ACK) {
|
||||
bool_t setError = RPDO->receiveError != (uint8_t)CO_RPDO_RX_OK;
|
||||
uint16_t code = (RPDO->receiveError == (uint8_t)CO_RPDO_RX_SHORT)
|
||||
if (RPDO->receiveError > CO_RPDO_RX_ACK) {
|
||||
bool_t setError = RPDO->receiveError != CO_RPDO_RX_OK;
|
||||
uint16_t code = (RPDO->receiveError == CO_RPDO_RX_SHORT)
|
||||
? CO_EMC_PDO_LENGTH : CO_EMC_PDO_LENGTH_EXC;
|
||||
CO_error(PDO->em, setError, CO_EM_RPDO_WRONG_LENGTH,
|
||||
code, PDO->dataLength);
|
||||
RPDO->receiveError = setError
|
||||
? (uint8_t)(CO_RPDO_RX_ACK_ERROR) : (uint8_t)(CO_RPDO_RX_ACK_NO_ERROR);
|
||||
? CO_RPDO_RX_ACK_ERROR : CO_RPDO_RX_ACK_NO_ERROR;
|
||||
}
|
||||
|
||||
/* Determine, which of the two rx buffers contains relevant message. */
|
||||
|
|
|
|||
|
|
@ -622,10 +622,9 @@ static bool_t readFromOd(CO_SDOserver_t *SDO,
|
|||
|
||||
/* load data from OD variable into the buffer */
|
||||
OD_size_t countRd = 0;
|
||||
uint8_t *bufShifted = SDO->buf + countRemain;
|
||||
|
||||
CO_LOCK_OD(SDO->CANdevTx);
|
||||
ODR_t odRet = SDO->OD_IO.read(&SDO->OD_IO.stream, bufShifted,
|
||||
ODR_t odRet = SDO->OD_IO.read(&SDO->OD_IO.stream, &SDO->buf[countRemain],
|
||||
countRdRequest, &countRd);
|
||||
CO_UNLOCK_OD(SDO->CANdevTx);
|
||||
|
||||
|
|
@ -636,9 +635,10 @@ static bool_t readFromOd(CO_SDOserver_t *SDO,
|
|||
}
|
||||
|
||||
/* if data is string, send only data up to null termination */
|
||||
OD_size_t lastRd = countRd + countRemain;
|
||||
if ((countRd > 0U) && ((SDO->OD_IO.stream.attribute & (OD_attr_t)ODA_STR) != 0U)) {
|
||||
bufShifted[countRd] = 0; /* (SDO->buf is one byte larger) */
|
||||
OD_size_t countStr = (OD_size_t)strlen((char *)bufShifted);
|
||||
SDO->buf[lastRd] = 0; /* (SDO->buf is one byte larger) */
|
||||
OD_size_t countStr = (OD_size_t)strlen((char *)&SDO->buf[countRemain]);
|
||||
if (countStr == 0U) { countStr = 1; }/* zero length is not allowed */
|
||||
if (countStr < countRd) {
|
||||
/* string terminator found, read is finished, shorten data */
|
||||
|
|
@ -747,8 +747,8 @@ CO_SDO_return_t CO_SDOserver_process(CO_SDOserver_t *SDO,
|
|||
/* if no error search object dictionary for new SDO request */
|
||||
if (abortCode == CO_SDO_AB_NONE) {
|
||||
ODR_t odRet;
|
||||
SDO->index = (((uint16_t)SDO->CANrxData[2]) << 8)
|
||||
| SDO->CANrxData[1];
|
||||
SDO->index = (uint16_t)((((uint16_t)SDO->CANrxData[2]) << 8)
|
||||
| SDO->CANrxData[1]);
|
||||
SDO->subIndex = SDO->CANrxData[3];
|
||||
odRet = OD_getSub(OD_find(SDO->OD, SDO->index), SDO->subIndex,
|
||||
&SDO->OD_IO, false);
|
||||
|
|
|
|||
128
MISRA.md
Normal file
128
MISRA.md
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
# MISRA Compliance
|
||||
|
||||
The CANopenNode files conform to the [MISRA C:2012](https://www.misra.org.uk)
|
||||
guidelines, with some noted exceptions. Compliance is checked with [PC Lint Plus](https://pclintplus.com/).
|
||||
|
||||
|
||||
## Configuration Inhibits Control
|
||||
|
||||
### Inhibits: Excluded the OD.c and OD.h files from the check because there are configuration parameters (not source code execution)
|
||||
```
|
||||
-efile( *, CANopenNode\OD.c )
|
||||
-efile( *, CANopenNode\OD.h )
|
||||
```
|
||||
|
||||
### Inhibits: C comment contains '://' sequence
|
||||
ref.: MISRA C 2012 Rule 3.1
|
||||
```
|
||||
-efile( 9259, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: unknown preprocessor directive 'string' in conditionally excluded region
|
||||
ref.: MISRA C 2012 Rule 20.13
|
||||
```
|
||||
-efile( 9160, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: conversion from pointer to void to other pointer type (type)
|
||||
ref.: MISRA C 2012 Rule 11.5
|
||||
```
|
||||
-efile( 9079, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: complete definition of symbol is unnecessary in this translation unit
|
||||
ref.: MISRA C 2012 Dir 4.8
|
||||
```
|
||||
-efile( 9045, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: function parameter symbol modified
|
||||
ref.: MISRA C 2012 Rule 17.8
|
||||
```
|
||||
-efile( 9044, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: cannot cast essential-type value to essential-type type
|
||||
ref.: MISRA C 2012 Rule 10.5
|
||||
```
|
||||
-efile( 9030, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: function-like macro, 'macro', defined
|
||||
ref.: MISRA C 2012 Dir 4.9
|
||||
```
|
||||
-efile( 9026, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: pasting/stringize operator used in definition of object-like/function-like macro 'string'
|
||||
ref.: MISRA C 2012 Rule 20.10
|
||||
```
|
||||
-efile( 9024, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: performing pointer arithmetic via addition/subtraction
|
||||
ref.: MISRA C 2012 Rule 18.4
|
||||
```
|
||||
-efile( 9016, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: local variable symbol could be pointer to const
|
||||
ref.: MISRA C 2012 Rule 8.13
|
||||
```
|
||||
-efile( 954, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: return statement before end of function symbol
|
||||
ref.: MISRA C 2012 Rule 15.5
|
||||
```
|
||||
-efile( 904, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: the left/right operand to operator always evaluates to 0
|
||||
ref.: MISRA C 2004 Rule 13.7
|
||||
```
|
||||
-efile( 845, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: previous value assigned to symbol not used
|
||||
```
|
||||
-efile( 838, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: zero given as string argument to operator context
|
||||
```
|
||||
-efile( 835, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: parameter symbol of function symbol could be pointer to const
|
||||
ref.: MISRA C 2012 Rule 8.13
|
||||
```
|
||||
-efile( 818, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: constant expression evaluates to 0 in 'unary/binary' operation 'operator'
|
||||
```
|
||||
-efile( 778, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: boolean condition for 'detail' always evaluates to 'detail'
|
||||
ref.: MISRA C 2012 Rule 2.2 and Rule 14.3
|
||||
```
|
||||
-efile( 774, CANopenNode* )
|
||||
```
|
||||
|
||||
### Inhibits: local macro 'string' not referenced
|
||||
ref.: MISRA C 2012 Rule 2.5
|
||||
```
|
||||
-efile( 750, CANopenNode* )
|
||||
```
|
||||
|
||||
|
||||
### Inhibits: constant value used in Boolean context (string)
|
||||
```
|
||||
-efile( 506, CANopenNode* )
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in a new issue