分析一些代码:
static volatile UCHAR *pucSndBufferCur;
eMBErrorCode eMBRTUSend( UCHAR ucSlaveAddress, const UCHAR * pucFrame, USHORT usLength )
{
if( eRcvState == STATE_RX_IDLE )
{
/* First byte before the Modbus-PDU is the slave address. */
pucSndBufferCur = ( UCHAR * ) pucFrame - 1;
/* Now copy the Modbus-PDU into the Modbus-Serial-Line-PDU. */
pucSndBufferCur[0] = ucSlaveAddress;
Run Code Online (Sandbox Code Playgroud)
看起来不安全,如果地址中的内存(pucFrame - 1)已用于其他变量并覆盖它可能会导致故障.
您怎么看?这样的代码可以使用还是错误的方式,永远不应该使用?