2017-04-15 48 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

謝謝你的提示,塞爾!在我們的C++診斷TODO中,我們已經有類似的情況,並且將在未來一段時間實現它,儘管我無法給你任何估計。