diff options
author | Saturneric <[email protected]> | 2022-03-19 08:42:47 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2022-03-19 08:42:47 +0000 |
commit | f8a513cee895e656563ca90297b46f21e1e1edb3 (patch) | |
tree | b4d45b801a1a4a25c15db8e6d44dd77f5bf0e8de /src/ui/thread/FileReadThread.cpp | |
parent | Merge branch 'develop-2.0.5' of github.com:saturneric/GpgFrontend into develo... (diff) | |
download | GpgFrontend-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/ui/thread/FileReadThread.cpp | 19 |
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"; } |