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: 421926 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 21EA114009B for ; Wed, 17 Dec 2014 00:44:50 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; q=dns; s=default; b=Hz62 c0DGFCY8bfllKTgY5K6jiIJ7NPunzZm0ERt6ORxib51iqtaFxL36q4CxxoExud4y DpjsNrG865bJO6ggimH4XADv5YCQGoPN+D81eJ9fTlZMIkJM2vCcQ/jHX7iwnsh3 L7tyQh27Rga5Ivd/kqlsZuXVnLBozBCJN9BrrbM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:in-reply-to; s=default; bh=GuCo+ducnf zPYUjvnfUxNocmYJs=; b=tiaUrZQNhkmtPu0DnRVLpRPLHYNllOgNDKNj3PEcCR R64eYzLlfGKthXuT1U5ud4vc0xHHwdvnhYW7f5/N8K7WhKZquaN5yTSgO+IBz5Vt FNqHjbmYHs9zVE2kllPzAOnRbsxXwCqfB0+2LjcZ1l1GOLVR9dzd3aW7X0xFVWgr 8= 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;