Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-1993

ContentSpecNode::getMaxTotalRange: Operator precedence flaw

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Duplicate
    • 3.1.1
    • None
    • Not relevant, C++ syntax problem

    Description

      ContentSpecType.cpp says at about line 260:

      if ((fType & 0x0f) == ContentSpecNode::Choice)

      { max = max * (maxFirst > maxSecond) ? maxFirst : maxSecond; }

      Thanks to operator precedence max evaluates either to maxFirst or maxSecond, but never to max*maxFirst or max*maxSecond.

      Adding parenthesis makes this do the right thing:
      max = max * ((maxFirst > maxSecond) ? maxFirst : maxSecond);

      Patch:
      — a/src/xercesc/validators/common/ContentSpecNode.cpp
      +++ b/src/xercesc/validators/common/ContentSpecNode.cpp
      @@ -259,7 +259,7 @@ int ContentSpecNode::getMaxTotalRange() const {
      else {

      if ((fType & 0x0f) == ContentSpecNode::Choice)

      { - max = max * (maxFirst > maxSecond) ? maxFirst : maxSecond; + max = max * ((maxFirst > maxSecond) ? maxFirst : maxSecond); }

      else {
      max = max * (maxFirst + maxSecond);

      Attachments

        1. ContentSpecNode.cpp.patch
          0.5 kB
          Michael Gmelin

        Activity

          People

            Unassigned Unassigned
            grembo Michael Gmelin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified