Package: cppcheck
Version: 2.14.0-1
Severity: important

Hi!

I just stumbled over the following issue after some code changes in
dpkg, which is currently failing one of its CI (the one in salsa)
due to this, but I'll modify the involved code to avoid this though.

It seems cppcheck does not handle correctly dereferencing a pointer
returned by a function, when said function gets passed a pointer by
reference.

Here's the smallest reproducer I could concoct:

  ,--- deref-return.c
  const char *func(int *data) {
          return "some string" + *data;
  }
  int main() {
          int data = 2;
          int *pdata = &data;
          if (func(&data)[0] == 'm')
                  return 0;
          return 1;
  }
  `---

  ,--- shell
  $ cppcheck deref-return.c
  Checking deref-return.c ...
  deref-return.c:7:12: error: Code '(& data' is invalid C code. Use --std or 
--language to configure the language. [syntaxError]
   if (func(&data)[0] == 'm')
             ^
  `---

If I change the call to «ref(pdata)[0]», then cppcheck is happy with
that.

Thanks,
Guillem

Reply via email to