0
sqlpp11을 사용하여 데이터베이스에 액세스하는 작은 응용 프로그램에서 버그가 발생했습니다. ASAN은 내가 API를 잘못 사용했기 때문에 사용 후 무료로 프로그램을 중단했습니다. 문제를 찾아내는 동안 나는 PVS에 성공하지 못한 시도를했다. 따라서 코드 스 니펫을 소프트웨어에 추가 검사를 추가 할 수있는 기회로 공유합니다.PVS studio에서 무료 사용 후 잘못된 사용을 찾지 못했습니다.
잘못된 코드이었다
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();