Fix #11117 FP nullPointerArithmetic when adding 0 (#4167)

This commit is contained in:
chrchr-github 2022-06-03 13:11:54 +02:00 committed by GitHub
parent 1a4bd0a7b3
commit 111f4e17da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -475,6 +475,9 @@ void CheckNullPointer::arithmetic()
continue;
if (numericOperand && numericOperand->valueType() && !numericOperand->valueType()->isIntegral())
continue;
const ValueFlow::Value* numValue = numericOperand ? numericOperand->getValue(0) : nullptr;
if (numValue && numValue->intvalue == 0) // don't warn for arithmetic with 0
continue;
const ValueFlow::Value* value = pointerOperand->getValue(0);
if (!value)
continue;

View File

@ -4209,6 +4209,17 @@ private:
"const char* get() const { return 0; }\n"
"void f(foo x) { if (get()) x += get(); }");
ASSERT_EQUALS("", errout.str());
check("typedef struct { uint8_t* buf, *buf_end; } S;\n" // #11117
"void f(S* s, uint8_t* buffer, int buffer_size) {\n"
" if (buffer_size < 0) {\n"
" buffer_size = 0;\n"
" buffer = NULL;\n"
" }\n"
" s->buf = buffer;\n"
" s->buf_end = s->buf + buffer_size;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void isPointerDeRefFunctionDecl() {