bug fix: NMEA/AIS/SeaTalk: cast functions with std::unique_ptr resulted in undefined...
commitc893e81944619d7eb11c0c749c73b7966918012a
authorMario Konrad <mario.konrad@gmx.net>
Thu, 20 Oct 2016 21:57:50 +0000 (20 23:57 +0200)
committerMario Konrad <mario.konrad@gmx.net>
Thu, 20 Oct 2016 21:57:50 +0000 (20 23:57 +0200)
tree1448ddbc2c0cf01e8489efdeacf645059daba223
parent35f70b9a5615d97590a7a5e82611adf33e861dfe
bug fix: NMEA/AIS/SeaTalk: cast functions with std::unique_ptr resulted in undefined behaviour.

This is an embarassing bug in the '*_cast' template functions which took ownership of
the 'std::unique_ptr' and returned a casted raw pointer. In the process the object was
deleted. Subsequent accesses through the returned pointer was access to freed heap
memory which is undefined behaviour.

From now on the 'sentence_cast' and 'message_cast' functions that take 'std::unique_ptr' as
argument, return a casted 'std::unique_ptr' which takes ownership. This has consequences
for the calling code if using the cast functions with 'std::unique_ptr' directly.

The raw pointer variants are not affected, obviously.
examples/read_ais.cpp
examples/read_nmea.cpp
src/marnav/ais/message.hpp
src/marnav/nmea/ais_helper.hpp
src/marnav/nmea/sentence.hpp
src/marnav/seatalk/message.hpp
src/nmeadump.cpp
test/ais/Test_ais_message_01.cpp
test/nmea/Test_nmea_dsc.cpp
test/nmea/Test_nmea_tll.cpp
test/test-ais-sample.cpp