RE: [xml] Test comparison fails on value (-2147483648)



-----Original Message-----
From: Daniel Veillard [mailto:veillard redhat com]
Sent: Sunday, August 26, 2001 3:54 PM
To: Chris_Poblete exchange dell com
Cc: xml gnome org
Subject: Re: [xml] Test comparison fails on value (-2147483648)


On Sun, Aug 26, 2001 at 12:37:55PM -0500, 
Chris_Poblete Dell com wrote:
VERSIONS: libxml2-2.4.3
          libxslt-1.0.3

PROBLEM:
The tag <xsl:when test="OutputWatts &lt; 0"> fails to 
evaluate correctly 
when OutputWatts is equal to -2147483648.  


Consider the ff. for the tag <xsl:when test="OutputWatts &lt; 0">
     OutputWatts            Evaluation
        -21474836                pass
        -214748364               pass
        -2147483648             (FAIL)
        -21474836489             pass
        -2147483648999           pass
        -2147483648999999999999  pass
The above values of OutputWatts are all negative numbers and
no matter how many digits there are, it fails at -2147483648
since an int is used temporary buffer.



  Well OutputWatts will evaluate to a nodeset which then once
used in the comparison will end up being casted to a float. 
OutputWatts
cannot be equal to -2147483648 but it's float value may be 
equal to this
 value.
  I hope you understand that this compare a set of XML nodes 
with a value.

PROPOSED RESOLUTION:
xpath:xmlXPathStringEvalNumber(6567)
------------------------------------------------------------
<   ret = (double) tmp;
----------
  ret = (double) tmp;
  // Variable tmp is declared as signed integer which may 
evaluate to
a negative
  // number.  We only need to calculate the absolute value of the
whole number since
  // any negative character in the input string has been flagged
separately.
  if (tmp < 0)
          ret = -ret;
------------------------------------------------------------

  This looks wrong to me. The sign is caught when beginning to parse
the string:

    if (*cur == '-') {
      isneg = 1;
      cur++;
    }

  Then before returning the value
    if (isneg) ret = -ret;

 If we apply you suggested change we change the sign twice in 
all cases,
looks wrong to me.
 The problem you're facing is an integer overflow. If you look at the
comment 5 lines before your suggested change you will get the 
explanation:

    /*
     * tmp is a workaroudn against a gcc compiler bug
     */

I spent a number of hours chasing it down and finding a 
workaround, your


Is there a reason why the function "atof" or "strtod" is not used instead?
These functions are supported in Linux, Windows, and Netware.
Sample code is:
{
  double retval;
  retval = strtod(str, (char**)NULL);
  if (retval == HUGE_VAL)
    return xmlXPathNAN;
  else
    return retval;
}


problem case don't doesn't seems realistic and I would prefer 
not change
that part of the code.

Daniel

-- 
Daniel Veillard      | Red Hat Network 
http://redhat.com/products/network/
veillard redhat com  | libxml Gnome XML XSLT toolkit  




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]