Skip to content

Commit

Permalink
ioctl_tree: Quiesce analyzer false positive
Browse files Browse the repository at this point in the history
It claims that

```
src/ioctl_tree.c:305:17: error: check of ‘node’ for NULL after already dereferencing it [-Werror=analyzer-deref-before-chec
k]
  305 |     for (; node != NULL; node = node->parent)
      |                 ^
  ‘ioctl_tree_next’: events 1-4
    |
    |  300 |     if (node->child != NULL)
    |      |        ~~~~~^~~~~~~
    |      |        |    |
    |      |        |    (1) pointer ‘node’ is dereferenced here
    |      |        (2) following ‘false’ branch...
    |  301 |         return node->child;
    |  302 |     if (node->next != NULL)
    |      |        ~~~~~~~~~~~
    |      |        |    |
    |      |        |    (3) ...to here
    |      |        (4) following ‘false’ branch...
    |
  ‘ioctl_tree_next’: event 5
    |
    |cc1:
    | (5): ...to here
    |
  ‘ioctl_tree_next’: event 6
    |
    |  305 |     for (; node != NULL; node = node->parent)
    |      |                 ^
    |      |                 |
    |      |                 (6) pointer ‘node’ is checked for NULL here but it was already dereferenced at (1)
```

But this is bogus -- the for loop first moves node to node->parent and
then checks against NULL. The same happens when rewriting it as a while
loop.
  • Loading branch information
martinpitt committed Jan 20, 2023
1 parent d38d1d9 commit 08bcdc1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/ioctl_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,17 @@ ioctl_tree_next(const ioctl_tree * node)
return node->child;
if (node->next != NULL)
return node->next;

/* HACK: -fanalyzer does not understand this loop */
#pragma GCC diagnostic push
#if !defined(__clang__)
#pragma GCC diagnostic ignored "-Wanalyzer-deref-before-check"
#endif
/* walk up the parents until we find an alternative sibling */
for (; node != NULL; node = node->parent)
if (node->next != NULL)
return node->next;
#pragma GCC diagnostic pop

/* no alternative siblings left, iteration done */
return NULL;
Expand Down

0 comments on commit 08bcdc1

Please sign in to comment.