2

我在 C 中有一个函数,其中包含以下行:

while (src=strstr(src,key)) {
        memmove(src,src+strlen(key),1+strlen(src+strlen(key)));
    }

当我运行 parasoft 来检查函数时,我从这些行中收到很多错误:

Not enclosed with brackets assignment was found in 'while' condition expression
LHS operand of '+' operator is 'unsigned long'
LHS operand of '+' operator is 'unsigned long'
LHS operand of '+' operator is 'unsigned long'
RHS operand of '+' operator is 'unsigned long'
RHS operand of '+' operator is 'unsigned long'
RHS operand of '+' operator is 'unsigned long'
Third param to 'memmove' function depends on second: src, key

你知道这些错误来自哪里吗?

4

1 回答 1

1

第一条消息是因为该工具怀疑您的意思是:

while (src == strstr(src, key)) {  /* comparison instead of assignment */

为了明确分配的目的,一些工具希望您编写

while ((src = strstr(src, key))) {
于 2016-03-03T08:31:49.977 回答