This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] gdb/microblaze-tdep.c: Check whether less than zero in conditional expression
- From: Chen Gang <gang dot chen dot 5i5j at gmail dot com>
- To: Michael Eager <eager at eagerm dot com>
- Cc: eager at eagercon dot com, binutils at sourceware dot org, gdb-patches at sourceware dot org
- Date: Thu, 24 Jul 2014 06:06:31 +0800
- Subject: Re: [PATCH] gdb/microblaze-tdep.c: Check whether less than zero in conditional expression
- Authentication-results: sourceware.org; auth=none
- References: <53CBCC2F dot 7040702 at gmail dot com> <53D01542 dot 9020107 at eagerm dot com>
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 <gang.chen.5i5j@gmail.com>
>> ---
>> 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).
> I do not see this error message in my build which uses -Wall.
> What is your build environment? Which version of GCC?
>
Originally, I use "CFLAGS=-W -g -O2" pass to configure. And '-W' is
different from '-Wall'. '-W' reports real 'all' warnings which can be
found by compiler, but '-Wall' reports most valuable warnings.
Thanks.
--
Chen Gang
Open share and attitude like air water and life which God blessed