#1056 [expr {" "}] inconsistentcy on Tru64

obsolete: 8.2.1
closed-fixed
nobody
2
2001-04-04
2000-10-26
Anonymous
No

OriginalBugID: 3378 Bug
Version: 8.2.1
SubmitDate: '1999-11-05'
LastModified: '2000-01-12'
Severity: SER
Status: Released
Submitter: techsupp
ChangedBy: hobbs
OS: Digital Unix
OSVersion: Compaq Tru64 Unix 5.0
FixedDate: '2000-01-12'
FixedInVersion: 8.3b2
ClosedDate: '2000-10-25'

Name:

Don Porter

Comments:

The root of the problem is an inconsistency in the implementation of

strtod() on Tru64 Unix 5.0. strtod(" ") returns 0.0 instead of an

indication that the conversion could not be performed. I'd argue that

this is a bug. The ANSI C spec says leading whitespace should be

ignored by strtod(), but the Tru64 implementation gives a different

result for strtod("") and strtod(" ").

The fix just adds a check for this bug to the configure script and

links in the compat/strtod.o to replace the buggy system one. A

test is added to the test suite to catch this problem.

ObservedBehavior:

On Linux, Solaris, Windows, ...

% puts ->[expr {" "}]<-

-> <-

% puts ->[expr {"\n"}]<-

->

<-

% expr { " " == "\n" }

0

BUT, on Compaq's Tru64 Unix 5.0....

% puts ->[expr {" "}]<-

0.0

% puts ->[expr {"\n"}]<-

0.0

% expr { " " == "\n" }

1

The last one is especially bad for any programmers who are

using "==" when they mean to use [string equal].

DesiredBehavior:

Consistent [expr] results on all platforms

Patch:

Index: tests/expr.test

===================================================================

RCS file: /cvsroot/tcl/tests/expr.test,v

retrieving revision 1.5.4.1

diff -c -r1.5.4.1 expr.test

*** expr.test 1999/09/22 04:12:57 1.5.4.1

--- expr.test 1999/10/14 21:28:27

***************

*** 647,652 ****

--- 647,655 ----

catch {expr int($x)}

expr {$x}

} 11

+ test expr-18.2 {whitespace strings should not be == 0 (buggy strtod)} {

+ expr {" "}

+ } { }

# Check "expr" and interpreter result object resetting before appending

# an error msg during evaluation of exprs not in {}s

Index: unix/configure.in

===================================================================

RCS file: /cvsroot/tcl/unix/configure.in,v

retrieving revision 1.48.2.1

diff -c -r1.48.2.1 configure.in

*** configure.in 1999/09/30 21:27:05 1.48.2.1

--- configure.in 1999/10/14 21:28:29

***************

*** 248,253 ****

--- 248,283 ----

fi

#--------------------------------------------------------------------

+ # Check for buggy strtod function. On Compaq's Tru64 Unix 5.0,

+ # strtod(" ") returns 0.0 instead of a failure to convert.

+ #--------------------------------------------------------------------

+

+ AC_CHECK_FUNC(strtod, tcl_strtod=1, tcl_strtod=0)

+ if test "$tcl_strtod" = 1; then

+ AC_MSG_CHECKING([for Tru64 strtod bug])

+ AC_TRY_RUN([

+ extern double strtod();

+ int main()

+ {

+ char *string = " ";

+ char *term;

+ double value;

+ value = strtod(string, &term);

+ if (term == (string+1)) {

+ exit(1);

+ }

+ exit(0);

+ }], tcl_ok=1, tcl_ok=0, tcl_ok=0)

+ if test "$tcl_ok" = 1; then

+ AC_MSG_RESULT(ok)

+ else

+ AC_MSG_RESULT(buggy)

+ test -n "$verbose" && echo " Adding strtod.o."

+ LIBOBJS="$LIBOBJS strtod.o"

+ fi

+ fi

+

+ #--------------------------------------------------------------------

# Under Solaris 2.4, strtod returns the wrong value for the

# terminating character under some conditions. Check for this

# and if the problem exists use a substitute procedure

PatchFiles:

tests/expr.test

unix/configure.in

These are folded in to the existing strtod checks, for both Tcl
and Tk.
-- 01/12/2000 hobbs

Discussion

  • Brent B. Welch
    Brent B. Welch
    2000-10-26

    • priority: 5 --> 2
    • status: open --> closed-fixed
     
  • Don Porter
    Don Porter
    2001-04-04

    • labels: 104235 --> 53. Configuration and Build Tools
    • summary: [expr {" "}] inconsistentcy on Tru64 --> [expr {" "}] inconsistentcy on Tru64