From: APTX Date: Mon, 27 Feb 2012 17:58:53 +0000 (+0100) Subject: Do not stall when hashing a 0 length file. X-Git-Url: https://gitweb.tyo.aptx.org/?a=commitdiff_plain;h=d25693f82fc5c21a2650493196646054e16fbf94;p=anidbudpclient.git Do not stall when hashing a 0 length file. --- diff --git a/hash.cpp b/hash.cpp index f8c46e3..c540ce6 100644 --- a/hash.cpp +++ b/hash.cpp @@ -108,11 +108,11 @@ void Hash::reportProgress(qint64 read, qint64 total) if (!fileQueue.first()) return; - int filePercent = (read * 100) / total; + int filePercent = total ? (read * 100) / total : 100; emit fileProgress(filePercent); emit fileQueue.first()->progress(filePercent); - int totalPercent = ((hashedFileSize + read) * 100) / totalFileSize; + int totalPercent = totalFileSize ? ((hashedFileSize + read) * 100) / totalFileSize : 100; emit progress(totalPercent); } diff --git a/hashproducer.cpp b/hashproducer.cpp index c81869c..473900f 100644 --- a/hashproducer.cpp +++ b/hashproducer.cpp @@ -60,13 +60,13 @@ qDebug() << "File exists, opening"; #endif if (file.open(QIODevice::ReadOnly)) { - while (!file.atEnd()) + do { if (abort) return; QByteArray data = file.read(ED2K_PART_SIZE); while (!(buffer->put(data, file.atEnd()) || abort)); - } + } while (!file.atEnd()); } }