From: Chen Gang <gang.chen.5i5j@gmail.com>
To: Michael Eager <eager@eagerm.com>, Michael Eager <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
Date: Thu, 24 Jul 2014 02:39:00 -0000 [thread overview]
Message-ID: <53D071D9.60503@gmail.com> (raw)
In-Reply-To: <53D06E5F.1070802@eagerm.com>
On 07/24/2014 10:24 AM, Michael Eager wrote:
> On 07/23/14 18:58, Chen Gang wrote:
>>
>>
>> On 07/24/2014 06:20 AM, Chen Gang wrote:
>>> 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 <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).
>>>>
>>>> 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)'.
>>>
>>
>> If what I said is correct, your idea/suggestions is still OK to me: easy
>> understanding has higher priority than keeping source code simple.
>
> Yes, you are correct. Took me a moment to think through.
>
OK, thank you for your work.
Thanks.
--
Chen Gang
Open, share, and attitude like air, water, and life which God blessed
next prev parent reply other threads:[~2014-07-24 2:39 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-20 14:03 Chen Gang
2014-07-23 20:04 ` Michael Eager
2014-07-23 22:06 ` Chen Gang
2014-07-23 22:17 ` Michael Eager
2014-07-23 22:20 ` Chen Gang
2014-07-24 1:58 ` Chen Gang
2014-07-24 2:24 ` Michael Eager
2014-07-24 2:39 ` Chen Gang [this message]
2014-07-31 18:55 ` Chen Gang
2014-07-31 21:53 ` Michael Eager
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53D071D9.60503@gmail.com \
--to=gang.chen.5i5j@gmail.com \
--cc=binutils@sourceware.org \
--cc=eager@eagercon.com \
--cc=eager@eagerm.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).