Skip to content

Commit

Permalink
Bugfix: missing return statement in custom ostream operator<< added
Browse files Browse the repository at this point in the history
When using clang, writing to output stream caused segmentation violation
because the stream object was not returned by the operator which has been
used just before.
Adding also some other return statements (though irrelevant for the crash).

Crash log
* thread #1: tid = 0x597d9, 0x0000000100001f7f testMessageList`void print_list<AliceO2::Format::messageList<TestMsg, SimpleHeader_t> >(list=<unavailable>, hdrsel=<unavailable>) + 191 at testMessageList.cxx:77, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
    frame #0: 0x0000000100001f7f testMessageList`void print_list<AliceO2::Format::messageList<TestMsg, SimpleHeader_t> >(list=<unavailable>, hdrsel=<unavailable>) + 191 at testMessageList.cxx:77
   74          it != list.end();
   75          ++it) {
   76       // the iterator defines a conversion operator to the header type
-> 77       std::cout << static_cast<typename ListType::header_type>(it) << std::end;
   78       // dereferencing of the iterator gives the payload
   79       std::cout << *it << std::end;
   80     }
  • Loading branch information
matthiasrichter authored and aphecetche committed Jul 13, 2016
1 parent bcf4739 commit 1925634
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions DataFormats/Generic/message_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class messageList {
const HdrT* srcHeader = reinterpret_cast<const HdrT*>(headerData);
// TODO: consistency check
mDataArray.push_back(messagePair(*srcHeader, payloadMsg));

return mDataArray.size();
}
/** number of data blocks in the list */
size_t size() {return mDataArray.size();}
Expand Down
4 changes: 4 additions & 0 deletions DataFormats/Generic/test/testMessageList.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ struct SimpleHeader_t {
std::ostream& operator<<(std::ostream& stream, SimpleHeader_t header) {
stream << "Header ID: " << header.id << std::endl;
stream << "Header Specification: " << std::hex << header.specification;

return stream;
}

// more complex message type, some class which wraps around payload
Expand All @@ -45,6 +47,8 @@ class TestMsg {
~TestMsg() {clear();}

int alloc(int size) {
// not yet implemented
return 0;
}

uint8_t* get() const {
Expand Down

0 comments on commit 1925634

Please sign in to comment.