#3996 Failure of string and expr commands

obsolete: 8.4.17
closed-invalid
5
2008-05-11
2008-05-11
Anonymous
No

I was trying to do some data validation, and ran across the following situation, which the example below demonstrates.

% info patchlevel
8.4.17
% set s "5\n"
5

% string is double -strict $s
1
% expr {$s >= 0.0}
1

The string 's' is clearly not a double since it contains a control character, however the string test for double is returning true, which it should fail. The expr command is even more puzzling since the string is not a number, but the comparison returns true.

IMHO both of these tests should return zero as the string is clearly not a double.

Discussion

  • Jeffrey Hobbs

    Jeffrey Hobbs - 2008-05-11
    • status: open --> closed-invalid
     
  • Jeffrey Hobbs

    Jeffrey Hobbs - 2008-05-11

    Logged In: YES
    user_id=72656
    Originator: NO

    To be clear, this control char is actually in the subspace of whitespace characters, which have more lenient handling at the C level. It is no different than " 5 ", which is 5 as a number to strtod.

    BTW, the comparison <= is dangerous because it can do string comparisons, but you will see that it is a valid "integer" by doing + 1 as well.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks