fix(storage): segfault during database migration

The akonadi-db-migrator tool reproducibly crashes with a segmentation fault (or a failed assertion if built in debug mode) while executing prepareDatabase() on the destination configuration.

The root cause is that both DbInitializer and DbUpdater expect SchemaVersionTable to be populated. This assumption is not met by a freshly created destination database: the table itself exists, but it is empty at this point. Consequently, SchemaVersion::retrieveAll() returns an empty list and the subsequent attempt to obtain its first element triggers an out-of-bounds read.

Fix the issue by checking for an empty result list in both places.

Refs: https://bugs.kde.org/show_bug.cgi?id=493393

Also add two clean-up commits for findings reported by clang-tidy and clazy.

Merge request reports

Loading