Skip to content

Commit 1d861af

Browse files
matthiasrichterMohammadAlTurany
authored andcommitted
Bugfix: missing return statement in custom ostream operator<< added
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 }
1 parent d525a09 commit 1d861af

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

DataFormats/Generic/message_list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ class messageList {
5656
const HdrT* srcHeader = reinterpret_cast<const HdrT*>(headerData);
5757
// TODO: consistency check
5858
mDataArray.push_back(messagePair(*srcHeader, payloadMsg));
59+
60+
return mDataArray.size();
5961
}
6062
/** number of data blocks in the list */
6163
size_t size() {return mDataArray.size();}

DataFormats/Generic/test/testMessageList.cxx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ struct SimpleHeader_t {
3131
std::ostream& operator<<(std::ostream& stream, SimpleHeader_t header) {
3232
stream << "Header ID: " << header.id << std::endl;
3333
stream << "Header Specification: " << std::hex << header.specification;
34+
35+
return stream;
3436
}
3537

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

4749
int alloc(int size) {
50+
// not yet implemented
51+
return 0;
4852
}
4953

5054
uint8_t* get() const {

0 commit comments

Comments
 (0)