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

Siddhesh Poyarekar siddhesh@redhat.com
Tue Dec 16 13:44:00 GMT 2014


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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/libc-alpha/attachments/20141216/f22a49a5/attachment.sig>


More information about the Libc-alpha mailing list