aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaturneric <[email protected]>2022-03-19 08:42:47 +0000
committerSaturneric <[email protected]>2022-03-19 08:42:47 +0000
commitf8a513cee895e656563ca90297b46f21e1e1edb3 (patch)
treeb4d45b801a1a4a25c15db8e6d44dd77f5bf0e8de
parentMerge branch 'develop-2.0.5' of github.com:saturneric/GpgFrontend into develo... (diff)
downloadGpgFrontend-f8a513cee895e656563ca90297b46f21e1e1edb3.tar.gz
GpgFrontend-f8a513cee895e656563ca90297b46f21e1e1edb3.zip
<fix>(core, ui): fix codacy issues.
1. The scope of the variable 'r' can be reduced. 2. Class 'IMAPFolder' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s). 3. Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20).
Diffstat (limited to '')
-rw-r--r--src/core/function/ArchiveFileOperator.cpp8
-rw-r--r--src/ui/mail/IMAPFolder.h13
-rw-r--r--src/ui/thread/FileReadThread.cpp19
-rw-r--r--src/ui/widgets/FindWidget.cpp2
4 files changed, 31 insertions, 11 deletions
diff --git a/src/core/function/ArchiveFileOperator.cpp b/src/core/function/ArchiveFileOperator.cpp
index 1a1ffaec..17f29df1 100644
--- a/src/core/function/ArchiveFileOperator.cpp
+++ b/src/core/function/ArchiveFileOperator.cpp
@@ -231,11 +231,11 @@ void GpgFrontend::ArchiveFileOperator::ExtractArchive(
LOG(ERROR) << "cannot read from stdin";
}
#ifdef WINDOWS
- if ((r = archive_read_open_filename_w(a, archive_path.wstring().c_str(),
- 10240))) {
+ if (archive_read_open_filename_w(a, archive_path.wstring().c_str(),
+ 10240) != ARCHIVE_OK) {
#else
- if ((r = archive_read_open_filename(a, archive_path.u8string().c_str(),
- 10240))) {
+ if (archive_read_open_filename(a, archive_path.u8string().c_str(),
+ 10240) != ARCHIVE_OK) {
#endif
LOG(ERROR) << "archive_read_open_filename() failed: "
<< archive_error_string(a);
diff --git a/src/ui/mail/IMAPFolder.h b/src/ui/mail/IMAPFolder.h
index 8d09eb94..94cb495d 100644
--- a/src/ui/mail/IMAPFolder.h
+++ b/src/ui/mail/IMAPFolder.h
@@ -49,6 +49,19 @@ class IMAPFolder {
explicit IMAPFolder(std::shared_ptr<vmime::net::folder> folder);
/**
+ * @brief Copy and construct the IMAPFolder object
+ */
+ IMAPFolder(const IMAPFolder &) = default;
+
+ /**
+ * @brief Copy the IMAPFolder object
+ */
+ * @return
+ */
+ IMAPFolder &operator=(const IMAPFolder &) = default;
+
+
+ /**
* @brief Set the Parent Folder object
*
* @param parent_node
diff --git a/src/ui/thread/FileReadThread.cpp b/src/ui/thread/FileReadThread.cpp
index 258b9405..83731c8a 100644
--- a/src/ui/thread/FileReadThread.cpp
+++ b/src/ui/thread/FileReadThread.cpp
@@ -47,18 +47,25 @@ void FileReadThread::run() {
if (is_regular_file(read_file_path)) {
LOG(INFO) << "read open" << read_file_path;
- QFile file;
- file.setFileName(QString::fromStdString(read_file_path.u8string()));
- file.open(QIODevice::ReadOnly);
+ QFile target_file;
+ target_file.setFileName(QString::fromStdString(read_file_path.u8string()));
+ target_file.open(QIODevice::ReadOnly);
QByteArray read_buffer;
LOG(INFO) << "thread start reading";
const size_t buffer_size = 4096;
- while ((read_buffer = file.read(buffer_size)).size() > 0) {
+ if(!(target_file.isOpen() && target_file.isReadable())) {
+ LOG(ERROR) << "file not open or not readable";
+ if(target_file.isOpen())
+ target_file.close();
+ return;
+ }
+
+ while (!target_file.atEnd() && (read_buffer = target_file.read(buffer_size)).size() > 0) {
// Check isInterruptionRequested
if (QThread::currentThread()->isInterruptionRequested()) {
LOG(INFO) << "thread is interruption requested ";
- file.close();
+ target_file.close();
return;
}
LOG(INFO) << "block size " << read_buffer.size();
@@ -71,7 +78,7 @@ void FileReadThread::run() {
QThread::msleep(128);
#endif
}
- file.close();
+ target_file.close();
emit SignalReadDone();
LOG(INFO) << "thread end reading";
}
diff --git a/src/ui/widgets/FindWidget.cpp b/src/ui/widgets/FindWidget.cpp
index 58ceda7c..defcf31c 100644
--- a/src/ui/widgets/FindWidget.cpp
+++ b/src/ui/widgets/FindWidget.cpp
@@ -59,7 +59,7 @@ FindWidget::FindWidget(QWidget* parent, PlainTextEditorPage* edit)
}
void FindWidget::set_background() {
- auto cursor = m_text_page_->GetTextPage()->textCursor();
+ // auto cursor = m_text_page_->GetTextPage()->textCursor();
// if match is found set background of QLineEdit to white, otherwise to red
QPalette bgPalette(find_edit_->palette());