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

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

  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
  I hope you understand that this compare a set of XML nodes with a value.

<     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
    if (tmp < 0)
            ret = -ret;

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

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

  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
problem case don't doesn't seems realistic and I would prefer not change
that part of the code.


Daniel Veillard      | Red Hat Network
veillard redhat com  | libxml Gnome XML XSLT toolkit | Rpmfind RPM search engine

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