Ticket UUID: | 634856 | |||
Title: | results of 'string is integer' are wrong | |||
Type: | Bug | Version: | None | |
Submitter: | bwallner | Created on: | 2002-11-07 07:36:46 | |
Subsystem: | 10. Objects | Assigned To: | hobbs | |
Priority: | 7 High | Severity: | ||
Status: | Closed | Last Modified: | 2002-11-19 09:29:14 | |
Resolution: | Fixed | Closed By: | hobbs | |
Closed on: | 2002-11-19 02:29:14 | |||
Description: |
I'm checking input values and see this strange behaviour of the 'string is integer' command. puts "tcl_version: $tcl_version" set numbers {1 +1 ++1 +-1 -+1 -1 --1 "- +1" "+ \n+1" "- \t-1"} foreach num $numbers { puts "$num is integer: [string is integer $num]" } See the results of '[string is real]': set numbers {1.0 +1.0 ++1.0 +-1.0 -+1.0 -1.0 --1.0 "- +1.0" "+ \n+1.0" "- \t-1.0"} foreach num $numbers { puts "$num is double: [string is double $num]" } | |||
User Comments: |
hobbs added on 2002-11-19 09:29:14:
Logged In: YES user_id=72656 corrected for 8.4.2. hobbs added on 2002-11-15 02:42:17: File Added - 35424: string634856.patch Logged In: YES user_id=72656 Attached is a patch which corrects this behavior in the head. I completely removed the funky functionality with #ifdef because I couldn't find a system to test a "bad strtoul" implementation. According to the C standard and reading of libc implementations, we shouldn't ever have this problem, but I left in at least the #ifdef in case someone finds such a system. kennykb added on 2002-11-07 23:48:01: Logged In: YES user_id=99768 The problem is actually in Tcl_GetIntFromObj, as the following shows. Note that literal sharing confuses the issue, since once the object acquires the integer internal representation that it shouldn't have, it keeps that internal rep. (bin) 49 % info patchlevel 8.4.0 (bin) 50 % set x "+ -1" + -1 (bin) 51 % expr { $x + 0 } can't use non-numeric string as operand of "+" (bin) 52 % set y [format %d $x] -1 (bin) 53 % set x + -1 (bin) 54 % expr { $x + 0 } -1 |
Attachments:
- string634856.patch [download] added by hobbs on 2002-11-15 02:42:17. [details]