From 963d71ae5759427a97e777da01d880a71b18fb18 Mon Sep 17 00:00:00 2001 From: Dmitry Yemanov Date: Sun, 19 Jan 2025 21:36:22 +0300 Subject: [PATCH] Misc --- src/jrd/CryptoManager.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/jrd/CryptoManager.cpp b/src/jrd/CryptoManager.cpp index 284c5c6ed2..9f19a30e50 100644 --- a/src/jrd/CryptoManager.cpp +++ b/src/jrd/CryptoManager.cpp @@ -54,10 +54,11 @@ using namespace Firebird; -namespace { +namespace +{ THREAD_ENTRY_DECLARE cryptThreadStatic(THREAD_ENTRY_PARAM p) { - Jrd::CryptoManager* cryptoManager = (Jrd::CryptoManager*) p; + const auto cryptoManager = (Jrd::CryptoManager*) p; cryptoManager->cryptThread(); return 0; @@ -68,12 +69,12 @@ namespace { const UCHAR CRYPT_CHANGE = LCK_PW; const UCHAR CRYPT_INIT = LCK_EX; - const int MAX_PLUGIN_NAME_LEN = 31; + constexpr int MAX_PLUGIN_NAME_LEN = sizeof(Ods::header_page::hdr_crypt_plugin) - 1; } -namespace Jrd { - +namespace Jrd +{ class Header { protected: @@ -625,9 +626,9 @@ namespace Jrd { void CryptoManager::changeCryptState(thread_db* tdbb, const string& plugName) { - if (plugName.length() > 31) + if (plugName.length() > MAX_PLUGIN_NAME_LEN) { - (Arg::Gds(isc_cp_name_too_long) << Arg::Num(31)).raise(); + (Arg::Gds(isc_cp_name_too_long) << Arg::Num(MAX_PLUGIN_NAME_LEN)).raise(); } const bool newCryptState = plugName.hasData(); @@ -656,8 +657,8 @@ namespace Jrd { // Nbak's lock was taken in prepareChangeCryptState() // If it was invalidated it's enough reason not to continue now - int bak_state = dbb.dbb_backup_manager->getState(); - if (bak_state != Ods::hdr_nbak_normal) + auto backupState = dbb.dbb_backup_manager->getState(); + if (backupState != Ods::hdr_nbak_normal) { (Arg::Gds(isc_wish_list) << Arg::Gds(isc_random) << "Cannot crypt: please wait for nbackup completion").raise(); @@ -669,7 +670,7 @@ namespace Jrd { (Arg::Gds(isc_cp_process_active)).raise(); } - bool headerCryptState = hdr->hdr_flags & Ods::hdr_encrypted; + const bool headerCryptState = hdr->hdr_flags & Ods::hdr_encrypted; if (headerCryptState == newCryptState) { (Arg::Gds(isc_cp_already_crypted)).raise();