Qpid
  1. Qpid
  2. QPID-3344

Comparisons of const DataAddr objects are incorrect

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.10
    • Fix Version/s: 0.13
    • Labels:
      None
    • Environment:

      Fedora 15, not that it matters.

      Description

      The following program results in incorrect output:

      test.cpp
      // g++ test.cpp -o test -lqmf2
      
      #include <qmf/DataAddr.h>
      #include <iostream>
      
      int main(void)
      {
          qmf::DataAddr foo("foo", "blarg", 1);
          const qmf::DataAddr bar("bar", "wibble", 2);
          
      
          // prints "false"
          std::cout << "foo == bar: " << (foo == bar ? "true" : "false") << "\n";
      
          // prints "true" (Doh!)
          std::cout << "bar == foo: " << (bar == foo ? "true" : "false") << "\n";
      
          return 0;
      }
      

      Anywhere where two DataAddr objects are compared and the first is a const reference will give a bogus result. (Specifically, both operands are converted to bool before being compared.) The reason is that DataAddr::operator==() is not declared const, so it will not be used to compare const references, and that C++ is pure, unadulterated evil.

      Not that qmf::Data::getAddr() returns a const qmf::DataAddr&, so this is likely to be a common problem. Some other APIs, such as qmf::AgentEvent::getDataAddr() return non-const references, which would be unaffected (unless they become const at some point in the call chain).

      A patch will follow presently.

        Activity

        Zane Bitter created issue -
        Hide
        Zane Bitter added a comment -

        The attached patch resolves the issue.

        Note that this will break the ABI.

        Show
        Zane Bitter added a comment - The attached patch resolves the issue. Note that this will break the ABI.
        Zane Bitter made changes -
        Field Original Value New Value
        Attachment qpid-DataAddr-const-compare.patch [ 12485590 ]
        Hide
        Zane Bitter added a comment -

        Inspection of the code suggests that qpid::store::QueueEntry is the only other class to be missing a const qualifier on operator==() or operator<(). However it does not contain any explicit type conversion operators, so the compiler should flag any problematic uses in that case. (It should probably still be fixed.)

        Show
        Zane Bitter added a comment - Inspection of the code suggests that qpid::store::QueueEntry is the only other class to be missing a const qualifier on operator==() or operator<(). However it does not contain any explicit type conversion operators, so the compiler should flag any problematic uses in that case. (It should probably still be fixed.)
        Hide
        Zane Bitter added a comment -

        I have attached a second patch which also resolves the issue while theoretically maintaining ABI stability.

        Show
        Zane Bitter added a comment - I have attached a second patch which also resolves the issue while theoretically maintaining ABI stability.
        Zane Bitter made changes -
        Ted Ross made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 0.13 [ 12316854 ]
        Resolution Fixed [ 1 ]
        Justin Ross made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Ted Ross
            Reporter:
            Zane Bitter
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development