0
我正在使用sqlpp11访问数据库时遇到了我的小应用程序中的一个错误。 ASAN免费使用后终止了该程序,因为我错误地使用了API。在试图找出我给PVS尝试没有成功的问题时。因此,我将代码片段分享为您在软件中添加额外支票的机会。PVS工作室未能在免费后发现错误的使用情况
不正确的代码是:
Record result; // this is the native struct
demo_dao::Record records; // this is the generated struct
auto const & record =
store.db (select (all_of (records)).from (records).where (record.id == static_cast<long> (id))).front();
// free has happened now
...
// use after free happens now
result.conditions = Conditions {record.Conditions.value()};
正确的用法是:
auto result = store.db (select (all_of (records)).from (records).where (record.id == static_cast<long> id)));
auto const & record = result.front();