From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17927 invoked by alias); 5 Sep 2005 02:16:37 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 17900 invoked by uid 22791); 5 Sep 2005 02:16:33 -0000 Received: from ausmtp02.au.ibm.com (HELO ausmtp02.au.ibm.com) (202.81.18.187) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Mon, 05 Sep 2005 02:16:33 +0000 Received: from sd0208e0.au.ibm.com (d23rh904.au.ibm.com [202.81.18.202]) by ausmtp02.au.ibm.com (8.12.10/8.12.10) with ESMTP id j852BBNW085998 for ; Mon, 5 Sep 2005 12:11:11 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.250.237]) by sd0208e0.au.ibm.com (8.12.10/NCO/VERS6.7) with ESMTP id j852JDDW150264 for ; Mon, 5 Sep 2005 12:19:14 +1000 Received: from d23av04.au.ibm.com (loopback [127.0.0.1]) by d23av04.au.ibm.com (8.12.11/8.13.3) with ESMTP id j852GF5N018421 for ; Mon, 5 Sep 2005 12:16:15 +1000 Received: from linux.cn.ibm.com (linux.cn.ibm.com [9.181.133.252]) by d23av04.au.ibm.com (8.12.11/8.12.11) with ESMTP id j852G9jC018315 for ; Mon, 5 Sep 2005 12:16:12 +1000 Date: Mon, 05 Sep 2005 02:16:00 -0000 From: Wu Zhou X-X-Sender: woodzltc@linux.site To: gdb-patches@sources.redhat.com Subject: [RFC] A patch for parse_number (c-exp.y) to recognize 1.25f Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2005-09/txt/msg00025.txt.bz2 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