Disable spurious -Warray-bounds for ypclnt.c (bug 26687)
DJ Delorie
dj@redhat.com
Fri Oct 30 20:18:50 GMT 2020
Joseph Myers <joseph@codesourcery.com> writes:
> Included among the GCC 11 warnings listed in bug 26687, but not fixed
> when that bug was marked as FIXED, are -Warray-bounds warnings in
> nis/ypclnt.c. These are all for different calls to the same piece of
> code, which already has a comment explaining that the element accessed
> is in a common prefix of the various structures. On the basis of that
> comment, this patch treats the warning as a false positive and
> disables it for that code.
Understood...
> diff --git a/nis/ypclnt.c b/nis/ypclnt.c
> +#include <libc-diag.h>
Ok.
> + DIAG_PUSH_NEEDS_COMMENT;
> + /* This cast results in a warning that a ypresp_val is partly
> + outside the bounds of the actual object referenced, but as
> + explained below only the stat element (in a common prefix) is
> + accessed. */
> + DIAG_IGNORE_NEEDS_COMMENT (11, "-Warray-bounds");
> if (status == YPERR_SUCCESS)
> /* We cast to ypresp_val although the pointer could also be of
> type ypresp_key_val or ypresp_master or ypresp_order or
> ypresp_maplist. But the stat element is in a common prefix so
> this does not matter. */
> status = ypprot_err (((struct ypresp_val *) resp)->stat);
> + DIAG_POP_NEEDS_COMMENT;
Ok. I suppose there are more "clever" ways of hiding this (as noted in
other emails, like supersets, etc) or even casting to ypstat* directly,
but this does what you intend nonetheless.
LGTM.
Reviewed-by: DJ Delorie <dj@redhat.com>
More information about the Libc-alpha
mailing list