Skip to content

Commit

Permalink
fix: compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
saturneric committed Dec 3, 2024
1 parent a8843bb commit f4525ea
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 46 deletions.
6 changes: 4 additions & 2 deletions src/core/function/gpg/GpgKeyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ auto GpgKeyManager::SetOwnerTrustLevel(const GpgKey& key,
}

auto GpgKeyManager::DeleteSubkey(const GpgKey& key, int subkey_index) -> bool {
if (subkey_index < 0 || subkey_index >= key.GetSubKeys()->size()) {
if (subkey_index < 0 ||
subkey_index >= static_cast<int>(key.GetSubKeys()->size())) {
LOG_W() << "illegal subkey index: " << subkey_index;
return false;
}
Expand Down Expand Up @@ -258,7 +259,8 @@ auto GpgKeyManager::DeleteSubkey(const GpgKey& key, int subkey_index) -> bool {
auto GpgKeyManager::RevokeSubkey(const GpgKey& key, int subkey_index,
int reason_code,
const QString& reason_text) -> bool {
if (subkey_index < 0 || subkey_index >= key.GetSubKeys()->size()) {
if (subkey_index < 0 ||
subkey_index >= static_cast<int>(key.GetSubKeys()->size())) {
LOG_W() << "illegal subkey index: " << subkey_index;
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions src/core/function/gpg/GpgKeyOpera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ auto GpgKeyOpera::SetExpire(const GpgKey& key, const SubkeyId& subkey_fpr,
err =
gpgme_op_setexpire(ctx_.DefaultContext(), static_cast<gpgme_key_t>(key),
expires_time, nullptr, 0);
assert(gpg_err_code(err) == GPG_ERR_NO_ERROR);
} else {
err =
gpgme_op_setexpire(ctx_.DefaultContext(), static_cast<gpgme_key_t>(key),
expires_time, subkey_fpr.toUtf8(), 0);
assert(gpg_err_code(err) == GPG_ERR_NO_ERROR);
}

return err;
Expand Down Expand Up @@ -200,6 +202,7 @@ void GpgKeyOpera::GenerateKey(const std::shared_ptr<GenKeyInfo>& params,

err = gpgme_op_createkey(ctx.DefaultContext(), userid.toUtf8(),
algo.toUtf8(), 0, expires, nullptr, flags);
assert(gpg_err_code(err) == GPG_ERR_NO_ERROR);

if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
data_object->Swap({GpgGenerateKeyResult{
Expand Down Expand Up @@ -240,6 +243,7 @@ auto GpgKeyOpera::GenerateKeySync(const std::shared_ptr<GenKeyInfo>& params)

err = gpgme_op_createkey(ctx.DefaultContext(), userid.toUtf8(),
algo.toUtf8(), 0, expires, nullptr, flags);
assert(gpg_err_code(err) == GPG_ERR_NO_ERROR);

if (CheckGpgError(err) == GPG_ERR_NO_ERROR) {
data_object->Swap({GpgGenerateKeyResult{
Expand Down Expand Up @@ -360,6 +364,7 @@ void GpgKeyOpera::GenerateKeyWithSubkey(

err = gpgme_op_createkey(ctx.DefaultContext(), userid, algo, 0, expires,
nullptr, flags);
assert(gpg_err_code(err) == GPG_ERR_NO_ERROR);

if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
data_object->Swap({GpgGenerateKeyResult{}});
Expand Down Expand Up @@ -441,6 +446,7 @@ auto GpgKeyOpera::GenerateKeyWithSubkeySync(

err = gpgme_op_createkey(ctx.DefaultContext(), userid, algo, 0, expires,
nullptr, flags);
assert(gpg_err_code(err) == GPG_ERR_NO_ERROR);

if (CheckGpgError(err) != GPG_ERR_NO_ERROR) {
data_object->Swap({GpgGenerateKeyResult{}});
Expand Down
4 changes: 2 additions & 2 deletions src/core/function/gpg/GpgUIDOperator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ auto GpgUIDOperator::AddUID(const GpgKey& key, const QString& name,
}

auto GpgUIDOperator::DeleteUID(const GpgKey& key, int uid_index) -> bool {
if (uid_index < 2 || uid_index > key.GetUIDs()->size()) {
if (uid_index < 2 || uid_index > static_cast<int>(key.GetUIDs()->size())) {
LOG_W() << "illegal uid_index index: " << uid_index;
return false;
}
Expand Down Expand Up @@ -144,7 +144,7 @@ auto GpgUIDOperator::DeleteUID(const GpgKey& key, int uid_index) -> bool {
auto GpgUIDOperator::RevokeUID(const GpgKey& key, int uid_index,
int reason_code,
const QString& reason_text) -> bool {
if (uid_index < 2 || uid_index > key.GetUIDs()->size()) {
if (uid_index < 2 || uid_index > static_cast<int>(key.GetUIDs()->size())) {
LOG_W() << "illegal uid index: " << uid_index;
return false;
}
Expand Down
5 changes: 2 additions & 3 deletions src/ui/dialog/import_export/ExportKeyPackageDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog(
// get suitable key ids
auto keys = GpgKeyGetter::GetInstance(current_gpg_context_channel_)
.GetKeys(key_ids_);
for (const auto& key : *keys) {
assert(key.IsGood());
}
assert(std::all_of(keys->begin(), keys->end(),
[](const auto& key) { return key.IsGood(); }));

auto keys_new_end =
std::remove_if(keys->begin(), keys->end(), [this](const auto& key) {
Expand Down
5 changes: 2 additions & 3 deletions src/ui/dialog/import_export/KeyUploadDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ KeyUploadDialog::KeyUploadDialog(int channel, const KeyIdArgsListPtr& keys_ids,
current_gpg_context_channel_(channel),
m_keys_(GpgKeyGetter::GetInstance(current_gpg_context_channel_)
.GetKeys(keys_ids)) {
for (const auto& key : *m_keys_) {
assert(key.IsGood());
}
assert(std::all_of(m_keys_->begin(), m_keys_->end(),
[](const auto& key) { return key.IsGood(); }));

auto* pb = new QProgressBar();
pb->setRange(0, 0);
Expand Down
5 changes: 2 additions & 3 deletions src/ui/dialog/keypair_details/KeyUIDSignDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ void KeyUIDSignDialog::slot_sign_key(bool clicked) {
auto key_ids = m_key_list_->GetChecked();
auto keys =
GpgKeyGetter::GetInstance(current_gpg_context_channel_).GetKeys(key_ids);
for (const auto& key : *keys) {
assert(key.IsGood());
}
assert(std::all_of(keys->begin(), keys->end(),
[](const auto& key) { return key.IsGood(); }));

auto expires = std::make_unique<QDateTime>(expires_edit_->dateTime());

Expand Down
10 changes: 4 additions & 6 deletions src/ui/main_window/KeyMgmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,8 @@ void KeyMgmt::SlotExportKeyToClipboard() {
auto keys =
GpgKeyGetter::GetInstance(key_list_->GetCurrentGpgContextChannel())
.GetKeys(keys_checked);
for (const auto& key : *keys) {
assert(key.IsGood());
}
assert(std::all_of(keys->begin(), keys->end(),
[](const auto& key) { return key.IsGood(); }));

CommonUtils::WaitForOpera(
this, tr("Exporting"), [=](const OperaWaitingHd& op_hd) {
Expand Down Expand Up @@ -504,9 +503,8 @@ void KeyMgmt::SlotExportAsOpenSSHFormat() {
auto keys =
GpgKeyGetter::GetInstance(key_list_->GetCurrentGpgContextChannel())
.GetKeys(keys_checked);
for (const auto& key : *keys) {
assert(key.IsGood());
}
assert(std::all_of(keys->begin(), keys->end(),
[](const auto& key) { return key.IsGood(); }));

CommonUtils::WaitForOpera(
this, tr("Exporting"), [this, keys](const OperaWaitingHd& op_hd) {
Expand Down
32 changes: 14 additions & 18 deletions src/ui/main_window/MainWindowFileSlotFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,8 @@ void MainWindow::SlotFileEncrypt(const QString& path) {
auto p_keys =
GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
.GetKeys(key_ids);
for (const auto& key : *p_keys) {
assert(key.IsGood());
}
assert(std::all_of(p_keys->begin(), p_keys->end(),
[](const auto& key) { return key.IsGood(); }));

// check key abilities
for (const auto& key : *p_keys) {
Expand Down Expand Up @@ -248,9 +247,8 @@ void MainWindow::SlotDirectoryEncrypt(const QString& path) {
auto p_keys =
GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
.GetKeys(key_ids);
for (const auto& key : *p_keys) {
assert(key.IsGood());
}
assert(std::all_of(p_keys->begin(), p_keys->end(),
[](const auto& key) { return key.IsGood(); }));

// check key abilities
for (const auto& key : *p_keys) {
Expand Down Expand Up @@ -415,9 +413,8 @@ void MainWindow::SlotFileSign(const QString& path) {
auto keys =
GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
.GetKeys(key_ids);
for (const auto& key : *keys) {
assert(key.IsGood());
}
assert(std::all_of(keys->begin(), keys->end(),
[](const auto& key) { return key.IsGood(); }));

if (keys->empty()) {
QMessageBox::critical(
Expand Down Expand Up @@ -578,9 +575,8 @@ void MainWindow::SlotFileEncryptSign(const QString& path) {
auto p_keys =
GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
.GetKeys(key_ids);
for (const auto& key : *p_keys) {
assert(key.IsGood());
}
assert(std::all_of(p_keys->begin(), p_keys->end(),
[](const auto& key) { return key.IsGood(); }));

if (p_keys->empty()) {
QMessageBox::critical(
Expand Down Expand Up @@ -640,9 +636,8 @@ void MainWindow::SlotFileEncryptSign(const QString& path) {
auto p_signer_keys =
GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
.GetKeys(signer_key_ids);
for (const auto& key : *p_signer_keys) {
assert(key.IsGood());
}
assert(std::all_of(p_signer_keys->begin(), p_signer_keys->end(),
[](const auto& key) { return key.IsGood(); }));

CommonUtils::WaitForOpera(
this, tr("Encrypting and Signing"), [=](const OperaWaitingHd& op_hd) {
Expand Down Expand Up @@ -697,9 +692,8 @@ void MainWindow::SlotDirectoryEncryptSign(const QString& path) {
auto p_keys =
GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
.GetKeys(key_ids);
for (const auto& key : *p_keys) {
assert(key.IsGood());
}
assert(std::all_of(p_keys->begin(), p_keys->end(),
[](const auto& key) { return key.IsGood(); }));

if (p_keys->empty()) {
QMessageBox::critical(
Expand Down Expand Up @@ -759,9 +753,11 @@ void MainWindow::SlotDirectoryEncryptSign(const QString& path) {
auto p_signer_keys =
GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
.GetKeys(signer_key_ids);
#ifndef NDEBUG
for (const auto& key : *p_signer_keys) {
assert(key.IsGood());
}
#endif

CommonUtils::WaitForOpera(
this, tr("Archiving & Encrypting & Signing"),
Expand Down
15 changes: 6 additions & 9 deletions src/ui/main_window/MainWindowGpgOperaFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ void MainWindow::SlotEncrypt() {
auto keys =
GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
.GetKeys(key_ids);
for (const auto& key : *keys) {
assert(key.IsGood());
}
assert(std::all_of(keys->begin(), keys->end(),
[](const auto& key) { return key.IsGood(); }));

for (const auto& key : *keys) {
if (!key.IsHasActualEncryptionCapability()) {
Expand Down Expand Up @@ -168,9 +167,8 @@ void MainWindow::SlotSign() {
auto keys =
GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
.GetKeys(key_ids);
for (const auto& key : *keys) {
assert(key.IsGood());
}
assert(std::all_of(keys->begin(), keys->end(),
[](const auto& key) { return key.IsGood(); }));

for (const auto& key : *keys) {
if (!key.IsHasActualSigningCapability()) {
Expand Down Expand Up @@ -384,9 +382,8 @@ void MainWindow::SlotEncryptSign() {
auto keys =
GpgKeyGetter::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
.GetKeys(key_ids);
for (const auto& key : *keys) {
assert(key.IsGood());
}
assert(std::all_of(keys->begin(), keys->end(),
[](const auto& key) { return key.IsGood(); }));

for (const auto& key : *keys) {
bool key_can_encrypt = key.IsHasActualEncryptionCapability();
Expand Down

0 comments on commit f4525ea

Please sign in to comment.