2017-04-15 3 views
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(); 

答えて

0

ありがとう!私たちは既にTODO for C++の診断で同様のケースを持っており、将来はいつでも実装する予定ですが、私はあなたに推測を与えることはできません。

関連する問題