[odb-users] reading value from default-constructed odb::nullable<T> causes undefined behaviour

Sten Kultakangas ratkaisut at gmail.com
Tue Apr 8 06:19:25 EDT 2025


Hello

I noticed random crashes of our application at the following line of code:
call->station_ext = seg.rdnis.get();

The type of rdnis is odb::nullable<std::string>

Apparently, the functionality of odb::nullable<T> (where T is non-trivially
constructible) has changed since commit 3795f78 ("Improve odb::nullable for
C++11 and later") for the cases when the ODB_CXX11 macro is enabled.

Since I don't know when the ODB_CXX11 macro was enabled by default, I am
not sure whether this change affected the production code that uses version
v2.5.0-b.27 or a later version. Could somebody confirm whether this
affected all the versions from v2.5.0-b.27 onwards?

Since calling get() of std::nullable<T> is a bad practice without checking
for the value returned by the null() member function first, I suggest
either throwing an exception or returning a default value of T, because
undefined behaviour is hard to track.

Best regards,
Sten Kultakangas


More information about the odb-users mailing list