我正在使用sqlpp11访问数据库的小应用程序中遇到一个错误。 ASAN在免费使用后中止了该程序,因为我错误地使用了API。在试图找出问题的同时,我尝试了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();
答案 0 :(得分:0)