This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix 'array subscript is above array bounds' warning in res_send.c

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?


	* 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)
-				if (ns >= MAXNS)
+				if (ns == MAXNS)
+				/* NS never exceeds MAXNS, but gcc 4.9 somehow
+				   does not see this.  */
+							   "-Warray-bounds");
 				EXT(statp).nsmap[ns] = n;
 				map[n] = ns++;
 		EXT(statp).nscount = n;

Attachment: pgpb3LBEaRD5g.pgp
Description: PGP signature

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]