BUILD: cebtree: silence a bogus gcc warning on impossible code paths

gcc-12 and above report a wrong warning about a negative length being
passed to memcmp() on an impossible code path when built at -O0. The
pattern is the same at a few places, basically:

  int foo(int op, const void *a, const void *b, size_t size, size_t arg)
  {
      if (op == 1) // arg is a strict multiple of size
          return memcmp(a, b, arg - size);
      return 0;
  }
  ...
  int bar()
  {
     return foo(0, a, b, sizeof(something), 0);
  }

It *might* be possible to invent dummy values for the "len" argument
above in the real code, but that significantly complexifies it and as
usual can easily result in introducing undesired bugs.

Here we take a different approach consisting in shutting the
-Wstringop-overread warning on gcc>=12 at -O0 since that's the only
condition that triggers it. The issue was reported to and confirmed by
the gcc team here:  https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114622

No backport needed, but this should be upstreamed into cebtree after
checking that all involved macros are available.
This commit is contained in:
Willy Tarreau 2024-09-17 17:27:44 +02:00
parent fcd6d29acf
commit 8df44eea6d

View File

@ -389,6 +389,14 @@ struct ceb_node *_cebu_descend(struct ceb_node **root,
int *ret_gpside,
struct ceb_node **ret_back)
{
#if !defined(__OPTIMIZE__) && __GNUC_PREREQ__(12, 0)
/* Avoid a bogus warning with gcc 12 and above: it warns about negative
* memcmp() length in non-existing code paths at -O0, as reported here:
* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114622
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overread"
#endif
struct ceb_node *p;
union ceb_key_storage *l, *r, *k;
struct ceb_node *gparent = NULL;
@ -1015,6 +1023,9 @@ struct ceb_node *_cebu_descend(struct ceb_node **root,
* caller to proceed since the element is not there.
*/
return NULL;
#if __GNUC_PREREQ__(12, 0)
#pragma GCC diagnostic pop
#endif
}