From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29979 invoked by alias); 23 Jul 2014 20:04:23 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 29955 invoked by uid 89); 23 Jul 2014 20:04:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: homiemail-a81.g.dreamhost.com Received: from sub5.mail.dreamhost.com (HELO homiemail-a81.g.dreamhost.com) (208.113.200.129) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 23 Jul 2014 20:04:20 +0000 Received: from homiemail-a81.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a81.g.dreamhost.com (Postfix) with ESMTP id D4B05A8072; Wed, 23 Jul 2014 13:04:18 -0700 (PDT) Received: from redwood.eagercon.com (c-24-7-16-38.hsd1.ca.comcast.net [24.7.16.38]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: eager@eagerm.com) by homiemail-a81.g.dreamhost.com (Postfix) with ESMTPSA id ADEA1A806F; Wed, 23 Jul 2014 13:04:18 -0700 (PDT) Message-ID: <53D01542.9020107@eagerm.com> Date: Wed, 23 Jul 2014 21:27:00 -0000 From: Michael Eager User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: Chen Gang , eager@eagercon.com CC: binutils@sourceware.org, gdb-patches@sourceware.org Subject: Re: [PATCH] gdb/microblaze-tdep.c: Check whether less than zero in conditional expression References: <53CBCC2F.7040702@gmail.com> In-Reply-To: <53CBCC2F.7040702@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2014-07/txt/msg00586.txt.bz2 On 07/20/14 07:03, Chen Gang wrote: > Use typecast 'size_t' on 'reg', not only avoid the related warning, but > also check whether less than zero -- for 'reg' is type 'int', and sizeof > (dwarf2_to_reg_map) is less than 0x7fff. > > It is quoted in gdb_assert(), so need check 'reg' whether less than zero. > And the related warning (with '-W'): > > ../../binutils-gdb/gdb/microblaze-tdep.c:667:3: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] > > ChangeLog: > > * microblaze-tdep.c (microblaze_dwarf2_reg_to_regnum): Check whether > less tha zero in conditional expression. > > > Signed-off-by: Chen Gang > --- > gdb/microblaze-tdep.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/gdb/microblaze-tdep.c b/gdb/microblaze-tdep.c > index 7e89241..9bec260 100644 > --- a/gdb/microblaze-tdep.c > +++ b/gdb/microblaze-tdep.c > @@ -664,7 +664,7 @@ static int dwarf2_to_reg_map[78] = > static int > microblaze_dwarf2_reg_to_regnum (struct gdbarch *gdbarch, int reg) > { > - gdb_assert (reg < sizeof (dwarf2_to_reg_map)); > + gdb_assert ((size_t) reg < sizeof (dwarf2_to_reg_map)); > return dwarf2_to_reg_map[reg]; > } I don't see anything in the patch which does what you describe, checking whether reg is less than zero. Converting a signed integer to an unsigned integer is not a way to check whether it is less than zero. This is better: + gdb_assert (reg >= 0 && (size_t) reg < sizeof (dwarf2_to_reg_map)); I do not see this error message in my build which uses -Wall. What is your build environment? Which version of GCC? -- Michael Eager eager@eagercon.com 1960 Park Blvd., Palo Alto, CA 94306 650-325-8077