public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Doug Evans <dje@google.com>
To: Andreas Schwab <schwab@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [patch] Handle 0 result from sscanf when parsing fp values.
Date: Tue, 17 Aug 2010 11:37:00 -0000	[thread overview]
Message-ID: <AANLkTimPfvoVFExCZLC4EytcjH=KarwpMost6CVn6XOx@mail.gmail.com> (raw)
In-Reply-To: <m3vd79hcti.fsf@hase.home>

On Tue, Aug 17, 2010 at 1:18 AM, Andreas Schwab <schwab@redhat.com> wrote:
> dje@google.com (Doug Evans) writes:
>
>> Index: objc-exp.y
>> ===================================================================
>> RCS file: /cvs/src/src/gdb/objc-exp.y,v
>> retrieving revision 1.38
>> diff -u -p -u -p -r1.38 objc-exp.y
>> --- objc-exp.y        5 Mar 2010 20:18:14 -0000       1.38
>> +++ objc-exp.y        17 Aug 2010 00:17:29 -0000
>> @@ -1016,8 +1016,9 @@ parse_number (p, len, parsed_float, puti
>>
>>        /* It's a float since it contains a point or an exponent.  */
>>
>> -      sscanf (p, "%" DOUBLEST_SCAN_FORMAT "%c",
>> -           &putithere->typed_val_float.dval, &c);
>> +      if (sscanf (p, "%" DOUBLEST_SCAN_FORMAT "%c",
>> +               &putithere->typed_val_float.dval, &c) != 1)
>
> Shouldn't that be "< 1" since there can be two conversions?
>
> Andreas.

Both p-exp.y and jv-exp.y check sscanf(...) != 1, the %c is there to
catch garbage after the number.
But it turns out p-exp.y and jv-exp.y are also broken in that they
assume the "f" in "1.1f" is accepted by sscanf as part of the number.
[They don't do what c-exp.y does which is capture the second
conversion as a string and check for valid vs invalid suffixes there.]
Blech.

I can see that if I'm going to test for sscanf(...) != 1 in objc-exp.y
I am going to have to nul-terminate the string first (as the other
*-exp.y files do).
Otherwise "p 1.1+1" will get flagged as an error.  I'll fix that.

As it turns out, in objective-c "1.1f" never makes it that far as the
caller to objc-exp.y:parse_number will flag 1.1f as an error and never
call parse_number.
I was prepared to fix "not checking result of sscanf", but I wasn't
going to fix all of them in this patch, and the closer I look the more
bugs I find.
Guess I'll (try to) fix them too.

  reply	other threads:[~2010-08-17 11:37 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-17  0:31 Doug Evans
2010-08-17  8:18 ` Andreas Schwab
2010-08-17 11:37   ` Doug Evans [this message]
2010-08-18 20:38     ` Doug Evans
2010-08-20  7:34       ` [patch] Fix new FAIL `reject p 0x1.1' [Re: [patch] Handle 0 result from sscanf when parsing fp values.] Jan Kratochvil
2010-08-20  7:37         ` [patch] Fix new FAIL `reject p 0x1.1' [fixup] " Jan Kratochvil
2010-08-20 11:58           ` Joseph S. Myers
2010-08-23 15:35             ` Doug Evans
2010-08-23 18:55               ` [patch] Fix new FAIL `reject p 0x1.1' [fixup] Jan Kratochvil
2010-08-23 19:49                 ` Doug Evans
2010-08-23 19:57                   ` Doug Evans
2010-08-31 19:38                     ` Jan Kratochvil
2010-08-31 22:51                       ` Doug Evans
2010-09-02 15:11                         ` Jan Kratochvil
2010-09-06 22:29                           ` Jan Kratochvil

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='AANLkTimPfvoVFExCZLC4EytcjH=KarwpMost6CVn6XOx@mail.gmail.com' \
    --to=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=schwab@redhat.com \
    /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).