From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18556 invoked by alias); 23 Jul 2014 22:20:28 -0000 Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org Received: (qmail 18536 invoked by uid 89); 23 Jul 2014 22:20:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-pd0-f179.google.com Received: from mail-pd0-f179.google.com (HELO mail-pd0-f179.google.com) (209.85.192.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 23 Jul 2014 22:20:27 +0000 Received: by mail-pd0-f179.google.com with SMTP id ft15so2399646pdb.38 for ; Wed, 23 Jul 2014 15:20:25 -0700 (PDT) X-Received: by 10.68.139.36 with SMTP id qv4mr5655280pbb.82.1406154025448; Wed, 23 Jul 2014 15:20:25 -0700 (PDT) Received: from [192.168.1.104] ([223.72.65.93]) by mx.google.com with ESMTPSA id o2sm3344793pdf.57.2014.07.23.15.20.23 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 23 Jul 2014 15:20:24 -0700 (PDT) Message-ID: <53D0352D.1020205@gmail.com> Date: Wed, 23 Jul 2014 22:20:00 -0000 From: Chen Gang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130625 Thunderbird/17.0.7 MIME-Version: 1.0 To: Michael Eager CC: Michael Eager , 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> <53D01542.9020107@eagerm.com> <53D031E7.40602@gmail.com> <53D03483.2060203@eagercon.com> In-Reply-To: <53D03483.2060203@eagercon.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2014-07/txt/msg00182.txt.bz2 On 07/24/2014 06:17 AM, Michael Eager wrote: > On 07/23/14 15:06, Chen Gang wrote: >> On 07/24/2014 04:04 AM, Michael Eager wrote: >>> 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)); >>> >> >> Yeah, it is common statement. It is also OK to me, although after type >> cast, 'reg >=0' can be omited (it can let code simpler, but let code >> not quit easy understanding). > > No, if you want to verify that the value is greater than zero, > this cannot be omitted. A negative value would converted to > a positive value by the cast. There no reason to believe that > this would cause the other half of the test to fail. > When an 'int' negative value converted to a positive value, it will be larger than 0x7fff which must be larget than 'sizeof (dwarf2_to_reg_map)'. Thanks. -- Chen Gang Open share and attitude like air water and life which God blessed