【发布时间】:2017-09-11 17:31:14
【问题描述】:
我的小应用程序使用sqlpp11 访问数据库时遇到了一个错误。 ASAN 在免费使用后中止了该程序,因为我使用了不正确的 API。在试图找出问题时,我尝试了 PVS,但没有成功。因此,我分享了代码 sn-p 作为在您的软件中添加额外检查的机会。
错误的代码是:
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();
【问题讨论】:
标签: pvs-studio