This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Fix 'array subscript is above array bounds' warning in res_send.c
- From: Adhemerval Zanella <azanella at linux dot vnet dot ibm dot com>
- To: libc-alpha at sourceware dot org
- Date: Tue, 16 Dec 2014 11:50:13 -0200
- Subject: Re: [PATCH] Fix 'array subscript is above array bounds' warning in res_send.c
- Authentication-results: sourceware.org; auth=none
- References: <20141216100950 dot GM30928 at spoyarek dot pnq dot redhat dot com> <mvm388fkifz dot fsf at hawking dot suse dot de> <20141216104514 dot GN30928 at spoyarek dot pnq dot redhat dot com> <mvmy4q7j20b dot fsf at hawking dot suse dot de> <20141216112624 dot GO30928 at spoyarek dot pnq dot redhat dot com> <5490254E dot 8060508 at linux dot vnet dot ibm dot com> <20141216125211 dot GW30928 at spoyarek dot pnq dot redhat dot com> <54902C9E dot 5030408 at linux dot vnet dot ibm dot com> <20141216130524 dot GX30928 at spoyarek dot pnq dot redhat dot com> <54902FB8 dot 8070006 at linux dot vnet dot ibm dot com> <20141216134432 dot GY30928 at spoyarek dot pnq dot redhat dot com>
On 16-12-2014 11:44, Siddhesh Poyarekar wrote:
> On Tue, Dec 16, 2014 at 11:12:24AM -0200, Adhemerval Zanella wrote:
>> In this loop 'ns' is initialized to '0' and updated on a simple while with
>> 2 constraints. Someone with more compiler background could correct me, but
>> I don't think this is really hard to compile evaluate that will fall
>> in 0 <= ns < MAXNS in all cases.
> Oh I see it now - N is initialized to EXT(statp).nscount, not NS :/
>
> I agree that this is a compiler issue. Here's a patch that undoes the
> change I made and adds DIAG_IGNORE_NEEDS_COMMENT instead. Does this
> look OK?
Looks ok, thanks!
>
> Siddhesh
>
> * resolv/res_send.c (__libc_res_nsend): Disable warning 'array
> subscript above bounds'.
>
> diff --git a/resolv/res_send.c b/resolv/res_send.c
> index 5a9882c..c35fb66 100644
> --- a/resolv/res_send.c
> +++ b/resolv/res_send.c
> @@ -429,9 +429,15 @@ __libc_res_nsend(res_state statp, const u_char *buf, int buflen,
> while (ns < MAXNS
> && EXT(statp).nsmap[ns] != MAXNS)
> ns++;
> - if (ns >= MAXNS)
> + if (ns == MAXNS)
> break;
> + /* NS never exceeds MAXNS, but gcc 4.9 somehow
> + does not see this. */
> + DIAG_PUSH_NEEDS_COMMENT;
> + DIAG_IGNORE_NEEDS_COMMENT (4.9,
> + "-Warray-bounds");
> EXT(statp).nsmap[ns] = n;
> + DIAG_POP_NEEDS_COMMENT;
> map[n] = ns++;
> }
> EXT(statp).nscount = n;