Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFC] A patch for parse_number (c-exp.y) to recognize 1.25f
@ 2005-09-05  2:16 Wu Zhou
  2005-09-15  8:35 ` Wu Zhou
  0 siblings, 1 reply; 4+ messages in thread
From: Wu Zhou @ 2005-09-05  2:16 UTC (permalink / raw)
  To: gdb-patches

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 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-09-20  9:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-05  2:16 [RFC] A patch for parse_number (c-exp.y) to recognize 1.25f Wu Zhou
2005-09-15  8:35 ` Wu Zhou
2005-09-17 20:44   ` Daniel Jacobowitz
2005-09-20  9:18     ` Wu Zhou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox