From patchwork Tue Dec 16 13:44:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 4273 Received: (qmail 18736 invoked by alias); 16 Dec 2014 13:44:44 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 18724 invoked by uid 89); 16 Dec 2014 13:44:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Date: Tue, 16 Dec 2014 19:14:32 +0530 From: Siddhesh Poyarekar To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, schwab@suse.de Subject: Re: [PATCH] Fix 'array subscript is above array bounds' warning in res_send.c Message-ID: <20141216134432.GY30928@spoyarek.pnq.redhat.com> References: <20141216100950.GM30928@spoyarek.pnq.redhat.com> <20141216104514.GN30928@spoyarek.pnq.redhat.com> <20141216112624.GO30928@spoyarek.pnq.redhat.com> <5490254E.8060508@linux.vnet.ibm.com> <20141216125211.GW30928@spoyarek.pnq.redhat.com> <54902C9E.5030408@linux.vnet.ibm.com> <20141216130524.GX30928@spoyarek.pnq.redhat.com> <54902FB8.8070006@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <54902FB8.8070006@linux.vnet.ibm.com> User-Agent: Mutt/1.5.22.1-rc1 (2013-10-16) 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? 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;