You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by "Zane Bitter (JIRA)" <ji...@apache.org> on 2011/07/07 15:40:16 UTC

[jira] [Created] (QPID-3344) Comparisons of const DataAddr objects are incorrect

Comparisons of const DataAddr objects are incorrect
---------------------------------------------------

                 Key: QPID-3344
                 URL: https://issues.apache.org/jira/browse/QPID-3344
             Project: Qpid
          Issue Type: Bug
          Components: Qpid Managment Framework
    Affects Versions: 0.10
         Environment: Fedora 15, not that it matters.
            Reporter: Zane Bitter
            Assignee: Ted Ross


The following program results in incorrect output:

{code:title=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;
}
{code}

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.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org


[jira] [Updated] (QPID-3344) Comparisons of const DataAddr objects are incorrect

Posted by "Zane Bitter (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/QPID-3344?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Zane Bitter updated QPID-3344:
------------------------------

    Attachment: qpid-DataAddr-const-compare.patch

The attached patch resolves the issue.

Note that this will break the ABI.

> Comparisons of const DataAddr objects are incorrect
> ---------------------------------------------------
>
>                 Key: QPID-3344
>                 URL: https://issues.apache.org/jira/browse/QPID-3344
>             Project: Qpid
>          Issue Type: Bug
>          Components: Qpid Managment Framework
>    Affects Versions: 0.10
>         Environment: Fedora 15, not that it matters.
>            Reporter: Zane Bitter
>            Assignee: Ted Ross
>         Attachments: qpid-DataAddr-const-compare.patch
>
>
> The following program results in incorrect output:
> {code:title=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;
> }
> {code}
> 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.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org


[jira] [Resolved] (QPID-3344) Comparisons of const DataAddr objects are incorrect

Posted by "Ted Ross (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/QPID-3344?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ted Ross resolved QPID-3344.
----------------------------

       Resolution: Fixed
    Fix Version/s: 0.13

> Comparisons of const DataAddr objects are incorrect
> ---------------------------------------------------
>
>                 Key: QPID-3344
>                 URL: https://issues.apache.org/jira/browse/QPID-3344
>             Project: Qpid
>          Issue Type: Bug
>          Components: Qpid Managment Framework
>    Affects Versions: 0.10
>         Environment: Fedora 15, not that it matters.
>            Reporter: Zane Bitter
>            Assignee: Ted Ross
>             Fix For: 0.13
>
>         Attachments: qpid-DataAddr-const-compare-ABI-stable.patch, qpid-DataAddr-const-compare.patch
>
>
> The following program results in incorrect output:
> {code:title=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;
> }
> {code}
> 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.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org


[jira] [Updated] (QPID-3344) Comparisons of const DataAddr objects are incorrect

Posted by "Zane Bitter (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/QPID-3344?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Zane Bitter updated QPID-3344:
------------------------------

    Attachment: qpid-DataAddr-const-compare-ABI-stable.patch

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

> Comparisons of const DataAddr objects are incorrect
> ---------------------------------------------------
>
>                 Key: QPID-3344
>                 URL: https://issues.apache.org/jira/browse/QPID-3344
>             Project: Qpid
>          Issue Type: Bug
>          Components: Qpid Managment Framework
>    Affects Versions: 0.10
>         Environment: Fedora 15, not that it matters.
>            Reporter: Zane Bitter
>            Assignee: Ted Ross
>         Attachments: qpid-DataAddr-const-compare-ABI-stable.patch, qpid-DataAddr-const-compare.patch
>
>
> The following program results in incorrect output:
> {code:title=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;
> }
> {code}
> 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.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org


[jira] [Commented] (QPID-3344) Comparisons of const DataAddr objects are incorrect

Posted by "Zane Bitter (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/QPID-3344?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13061335#comment-13061335 ] 

Zane Bitter commented on QPID-3344:
-----------------------------------

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.)

> Comparisons of const DataAddr objects are incorrect
> ---------------------------------------------------
>
>                 Key: QPID-3344
>                 URL: https://issues.apache.org/jira/browse/QPID-3344
>             Project: Qpid
>          Issue Type: Bug
>          Components: Qpid Managment Framework
>    Affects Versions: 0.10
>         Environment: Fedora 15, not that it matters.
>            Reporter: Zane Bitter
>            Assignee: Ted Ross
>         Attachments: qpid-DataAddr-const-compare.patch
>
>
> The following program results in incorrect output:
> {code:title=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;
> }
> {code}
> 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.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org