This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFC] A patch for parse_number (c-exp.y) to recognize 1.25f
- From: Wu Zhou <woodzltc at cn dot ibm dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Mon, 5 Sep 2005 10:09:18 +0800 (CST)
- Subject: [RFC] A patch for parse_number (c-exp.y) to recognize 1.25f
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