Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Wu Zhou <woodzltc@cn.ibm.com>
To: gdb-patches@sources.redhat.com
Subject: [RFC] A patch for parse_number (c-exp.y) to recognize 1.25f
Date: Mon, 05 Sep 2005 02:16:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.63.0509050946590.10325@linux.site> (raw)

Hello all,

I just found a problem in gdb that its c-parser take 1.25f as invalid 
number.  After taking some look at the source code, I found that the error 
lies in the following code:

  if (parsed_float)
    {
      /* It's a float since it contains a point or an exponent.  */
      char c;
      int num = 0;      /* number of tokens scanned by scanf */
      char saved_char = p[len];

      p[len] = 0;       /* null-terminate the token */
      if (sizeof (putithere->typed_val_float.dval) <= sizeof (float))
        num = sscanf (p, "%g%c", (float *) &putithere->typed_val_float.dval,&c);
......
      p[len] = saved_char;      /* restore the input stream */
      if (num != 1)             /* check scanf found ONLY a float ... */
        return ERROR;

So I code a simple patch to let it recognize 1.25f or 1.25l correctly:

Index: c-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/c-exp.y,v
retrieving revision 1.29
diff -c -3 -p -r1.29 c-exp.y
*** c-exp.y	8 Mar 2005 14:35:17 -0000	1.29
--- c-exp.y	5 Sep 2005 01:51:10 -0000
*************** parse_number (p, len, parsed_float, puti
*** 1097,1103 ****
  #endif
  	}
        p[len] = saved_char;	/* restore the input stream */
!       if (num != 1) 		/* check scanf found ONLY a float ... */
  	return ERROR;
        /* See if it has `f' or `l' suffix (float or long double).  */
  
--- 1097,1103 ----
  #endif
  	}
        p[len] = saved_char;	/* restore the input stream */
!       if (num != 1 && num != 2) 	/* check scanf found ONLY a float ... */
  	return ERROR;
        /* See if it has `f' or `l' suffix (float or long double).  */
  

This is the least intrusive way for GDB to recognize 1.25f as I think.  
But it still have a problem: it might handle 1.25df (or 1.25ddf and so on) 
as also a valid number and transfer it to 1.25.  So do we need to 
eliminate this kind of false-positive? 

To fix this kind of false-negative and not to introduce false-positive, I 
am thinking of changing the second format in sscanf to "%s" (string).  
Thus the parser could get the trailing characters following the float. 
Then we can add some code to parse them to eliminate false-positive.  Any 
points on this idea?  Is it worthwhile to do this?  Please comment.  TIA.

Regards
- Wu Zhou 


             reply	other threads:[~2005-09-05  2:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-05  2:16 Wu Zhou [this message]
2005-09-15  8:35 ` Wu Zhou
2005-09-17 20:44   ` Daniel Jacobowitz
2005-09-20  9:18     ` Wu Zhou

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=Pine.LNX.4.63.0509050946590.10325@linux.site \
    --to=woodzltc@cn.ibm.com \
    --cc=gdb-patches@sources.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