警告665:宏'SET_RECORD'中的未填充参数2传递一个表达式

时间:2014-02-11 12:43:58

标签: c++ lint

这是我的代码库的一部分...
因为在MACRO调用中缩进/分组变量以避免lint警告是令人困惑的 代码:

 enum baseId{
    ADDRESS_ID = 0,
    ML_ID
    };
 struct strAddress{
        uint8   Address[6];
    };
 struct strCam{
        FLOAT         currXmm;
        FLOAT         currYmm;
    };
#define SET_RECORD(recordid, bufferptr, type)     {               \
RecordReturnType           status;                        \
RecordManager<type> sampleRecord;                     \
validate(bufferptr != NULL);                          \
status = sampleRecord.SetRecord(recordid, *(type *) (const_cast<void *>(bufferptr))\
         );                           \
validate(status == E_OK);                         \
}

bool fun(const uint8 *diagData){
    bool ret ;
    strAddress tempMac;
    memcpy(tempMac.Address, diagData,sizeof(strAddress));
    SET_RECORD((uint32)ADDRESS_ID,(const void *) &tempMac,strAddress); //line
        ret = TRUE;             
    }

Warning 665: Unparenthesized parameter 2 in macro 'SET_RECORD' is passed an expression

评论//线是这个警告出现的地方caz ...我尝试以不同的方式对第二个变量进行括号,但仍然警告仍然存在......

2 个答案:

答案 0 :(得分:3)

显然,Lint警告你宏的第4行,validate(bufferptr != NULL);。如果bufferptr绑定到包含优先级低于!=的运算符的表达式,则宏将扩展为您可能不期望的值:

SET_RECORD(x, condition ? thisbuf : thatbuf, y)扩展为:validate(condition ? thisbuf : thatbuf != NULL);,表示validate(condition ? thisbuf : (thatbuf != NULL));

重写这一行:validate((bufferptr) != NULL);

答案 1 :(得分:0)

每次在宏中使用时,都会通过括号括起宏参数以避免此类问题:https://servicios.excentia.es/sonar-demo/rules/show/pclint:665?layout=true

相关问题