aboutsummaryrefslogtreecommitdiffstats
path: root/src/ui/thread/FileReadThread.cpp
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 /src/ui/thread/FileReadThread.cpp
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 'src/ui/thread/FileReadThread.cpp')
-rw-r--r--src/ui/thread/FileReadThread.cpp19
1 files changed, 13 insertions, 6 deletions
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";
}