Fixes for minor issues found by static analysis

Mostly style issues.

I used the following tools to find most of these:

- lgtm.com
- clang-tidy
- cpplint
- cppcheck
This commit is contained in:
Carlo Teubner 2019-11-24 14:40:16 +00:00 committed by Jonathan White
parent c663b5d5fc
commit f62e0534a2
6 changed files with 18 additions and 24 deletions

View File

@ -485,10 +485,6 @@ KeySym AutoTypePlatformX11::keyToKeySym(Qt::Key key)
*/ */
void AutoTypePlatformX11::updateKeymap() void AutoTypePlatformX11::updateKeymap()
{ {
int keycode, inx;
int mod_index, mod_key;
XModifierKeymap* modifiers;
if (m_xkb) { if (m_xkb) {
XkbFreeKeyboard(m_xkb, XkbAllComponentsMask, True); XkbFreeKeyboard(m_xkb, XkbAllComponentsMask, True);
} }
@ -500,10 +496,9 @@ void AutoTypePlatformX11::updateKeymap()
m_keysymTable = XGetKeyboardMapping(m_dpy, m_minKeycode, m_maxKeycode - m_minKeycode + 1, &m_keysymPerKeycode); m_keysymTable = XGetKeyboardMapping(m_dpy, m_minKeycode, m_maxKeycode - m_minKeycode + 1, &m_keysymPerKeycode);
/* determine the keycode to use for remapped keys */ /* determine the keycode to use for remapped keys */
inx = (m_remapKeycode - m_minKeycode) * m_keysymPerKeycode;
if (m_remapKeycode == 0 || !isRemapKeycodeValid()) { if (m_remapKeycode == 0 || !isRemapKeycodeValid()) {
for (keycode = m_minKeycode; keycode <= m_maxKeycode; keycode++) { for (int keycode = m_minKeycode; keycode <= m_maxKeycode; keycode++) {
inx = (keycode - m_minKeycode) * m_keysymPerKeycode; int inx = (keycode - m_minKeycode) * m_keysymPerKeycode;
if (m_keysymTable[inx] == NoSymbol) { if (m_keysymTable[inx] == NoSymbol) {
m_remapKeycode = keycode; m_remapKeycode = keycode;
m_currentRemapKeysym = NoSymbol; m_currentRemapKeysym = NoSymbol;
@ -513,11 +508,11 @@ void AutoTypePlatformX11::updateKeymap()
} }
/* determine the keycode to use for modifiers */ /* determine the keycode to use for modifiers */
modifiers = XGetModifierMapping(m_dpy); XModifierKeymap* modifiers = XGetModifierMapping(m_dpy);
for (mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index++) { for (int mod_index = ShiftMapIndex; mod_index <= Mod5MapIndex; mod_index++) {
m_modifier_keycode[mod_index] = 0; m_modifier_keycode[mod_index] = 0;
for (mod_key = 0; mod_key < modifiers->max_keypermod; mod_key++) { for (int mod_key = 0; mod_key < modifiers->max_keypermod; mod_key++) {
keycode = modifiers->modifiermap[mod_index * modifiers->max_keypermod + mod_key]; int keycode = modifiers->modifiermap[mod_index * modifiers->max_keypermod + mod_key];
if (keycode) { if (keycode) {
m_modifier_keycode[mod_index] = keycode; m_modifier_keycode[mod_index] = keycode;
break; break;

View File

@ -29,7 +29,7 @@ class ScreenLockListenerWin : public ScreenLockListenerPrivate, public QAbstract
public: public:
explicit ScreenLockListenerWin(QWidget* parent = nullptr); explicit ScreenLockListenerWin(QWidget* parent = nullptr);
~ScreenLockListenerWin(); ~ScreenLockListenerWin();
virtual bool nativeEventFilter(const QByteArray& eventType, void* message, long*) override; bool nativeEventFilter(const QByteArray& eventType, void* message, long*) override;
private: private:
void* m_powerNotificationHandle; void* m_powerNotificationHandle;

View File

@ -35,6 +35,7 @@
IconStruct::IconStruct() IconStruct::IconStruct()
: uuid(QUuid()) : uuid(QUuid())
, number(0) , number(0)
, applyTo(ApplyIconToOptions::THIS_ONLY)
{ {
} }

View File

@ -214,9 +214,9 @@ MainWindow::MainWindow()
setWindowIcon(filePath()->applicationIcon()); setWindowIcon(filePath()->applicationIcon());
m_ui->globalMessageWidget->setHidden(true); m_ui->globalMessageWidget->setHidden(true);
// clang-format off // clang-format off
connect(m_ui->globalMessageWidget, &MessageWidget::linkActivated, &MessageWidget::openHttpUrl); connect(m_ui->globalMessageWidget, &MessageWidget::linkActivated, &MessageWidget::openHttpUrl);
connect(m_ui->globalMessageWidget, SIGNAL(showAnimationStarted()), m_ui->globalMessageWidgetContainer, SLOT(show())); connect(m_ui->globalMessageWidget, SIGNAL(showAnimationStarted()), m_ui->globalMessageWidgetContainer, SLOT(show()));
connect(m_ui->globalMessageWidget, SIGNAL(hideAnimationFinished()), m_ui->globalMessageWidgetContainer, SLOT(hide())); connect(m_ui->globalMessageWidget, SIGNAL(hideAnimationFinished()), m_ui->globalMessageWidgetContainer, SLOT(hide()));
// clang-format on // clang-format on
m_clearHistoryAction = new QAction(tr("Clear history"), m_ui->menuFile); m_clearHistoryAction = new QAction(tr("Clear history"), m_ui->menuFile);
@ -483,10 +483,8 @@ MainWindow::MainWindow()
#endif #endif
// clang-format off // clang-format off
connect(m_ui->tabWidget, connect(m_ui->tabWidget, SIGNAL(messageGlobal(QString,MessageWidget::MessageType)),
SIGNAL(messageGlobal(QString,MessageWidget::MessageType)), SLOT(displayGlobalMessage(QString,MessageWidget::MessageType)));
this,
SLOT(displayGlobalMessage(QString,MessageWidget::MessageType)));
// clang-format on // clang-format on
connect(m_ui->tabWidget, SIGNAL(messageDismissGlobal()), this, SLOT(hideGlobalMessage())); connect(m_ui->tabWidget, SIGNAL(messageDismissGlobal()), this, SLOT(hideGlobalMessage()));
@ -1322,7 +1320,7 @@ void MainWindow::toggleWindow()
// see https://github.com/keepassxreboot/keepassxc/issues/271 // see https://github.com/keepassxreboot/keepassxc/issues/271
// and https://bugreports.qt.io/browse/QTBUG-58723 // and https://bugreports.qt.io/browse/QTBUG-58723
// check for !isVisible(), because isNativeMenuBar() does not work with appmenu-qt5 // check for !isVisible(), because isNativeMenuBar() does not work with appmenu-qt5
const static auto isDesktopSessionUnity = qgetenv("XDG_CURRENT_DESKTOP") == "Unity"; static const auto isDesktopSessionUnity = qgetenv("XDG_CURRENT_DESKTOP") == "Unity";
if (isDesktopSessionUnity && Tools::qtRuntimeVersion() < QT_VERSION_CHECK(5, 9, 0) if (isDesktopSessionUnity && Tools::qtRuntimeVersion() < QT_VERSION_CHECK(5, 9, 0)
&& !m_ui->menubar->isVisible()) { && !m_ui->menubar->isVisible()) {

View File

@ -98,10 +98,10 @@ MessageBox::Button MessageBox::messageBox(QWidget* parent,
for (uint64_t b = First; b <= Last; b <<= 1) { for (uint64_t b = First; b <= Last; b <<= 1) {
if (b & buttons) { if (b & buttons) {
QString text = m_buttonDefs[static_cast<Button>(b)].first; QString buttonText = m_buttonDefs[static_cast<Button>(b)].first;
QMessageBox::ButtonRole role = m_buttonDefs[static_cast<Button>(b)].second; QMessageBox::ButtonRole role = m_buttonDefs[static_cast<Button>(b)].second;
auto buttonPtr = msgBox.addButton(text, role); auto buttonPtr = msgBox.addButton(buttonText, role);
m_addedButtonLookup.insert(buttonPtr, static_cast<Button>(b)); m_addedButtonLookup.insert(buttonPtr, static_cast<Button>(b));
} }
} }

View File

@ -279,7 +279,6 @@ void TestSymmetricCipher::testTwofish256CbcEncryption()
QByteArray::fromHex("6F725C5950133F82EF021A94CADC8508")}; QByteArray::fromHex("6F725C5950133F82EF021A94CADC8508")};
SymmetricCipher cipher(SymmetricCipher::Twofish, SymmetricCipher::Cbc, SymmetricCipher::Encrypt); SymmetricCipher cipher(SymmetricCipher::Twofish, SymmetricCipher::Cbc, SymmetricCipher::Encrypt);
bool ok;
for (int i = 0; i < keys.size(); ++i) { for (int i = 0; i < keys.size(); ++i) {
QVERIFY(cipher.init(keys[i], ivs[i])); QVERIFY(cipher.init(keys[i], ivs[i]));
@ -287,6 +286,7 @@ void TestSymmetricCipher::testTwofish256CbcEncryption()
QByteArray ctPrev = ivs[i]; QByteArray ctPrev = ivs[i];
QByteArray ctCur; QByteArray ctCur;
QCOMPARE(cipher.blockSize(), 16); QCOMPARE(cipher.blockSize(), 16);
bool ok = false;
for (int j = 0; j < 5000; ++j) { for (int j = 0; j < 5000; ++j) {
ctCur = cipher.process(ptNext, &ok); ctCur = cipher.process(ptNext, &ok);
if (!ok) { if (!ok) {
@ -335,13 +335,13 @@ void TestSymmetricCipher::testTwofish256CbcDecryption()
QByteArray::fromHex("4C81F5BDC1081170FF96F50B1F76A566")}; QByteArray::fromHex("4C81F5BDC1081170FF96F50B1F76A566")};
SymmetricCipher cipher(SymmetricCipher::Twofish, SymmetricCipher::Cbc, SymmetricCipher::Decrypt); SymmetricCipher cipher(SymmetricCipher::Twofish, SymmetricCipher::Cbc, SymmetricCipher::Decrypt);
bool ok;
for (int i = 0; i < keys.size(); ++i) { for (int i = 0; i < keys.size(); ++i) {
cipher.init(keys[i], ivs[i]); cipher.init(keys[i], ivs[i]);
QByteArray ctNext = cipherTexts[i]; QByteArray ctNext = cipherTexts[i];
QByteArray ptCur; QByteArray ptCur;
QCOMPARE(cipher.blockSize(), 16); QCOMPARE(cipher.blockSize(), 16);
bool ok = false;
for (int j = 0; j < 5000; ++j) { for (int j = 0; j < 5000; ++j) {
ptCur = cipher.process(ctNext, &ok); ptCur = cipher.process(ctNext, &ok);
if (!ok) { if (!ok) {