From 1dbb1817e84182dbd04179e24f1c2bfbf776633f Mon Sep 17 00:00:00 2001 From: David Sansome Date: Thu, 12 Aug 2010 16:35:43 +0000 Subject: [PATCH] Codereview comments from r1685 --- src/core/utilities.cpp | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/core/utilities.cpp b/src/core/utilities.cpp index 60aa95ce8..f9401604f 100644 --- a/src/core/utilities.cpp +++ b/src/core/utilities.cpp @@ -28,6 +28,8 @@ # include #endif +#include + namespace Utilities { static QString tr(const char* str) { @@ -144,35 +146,28 @@ bool Copy(QIODevice* source, QIODevice* destination) { return false; const qint64 bytes = source->size(); - char* data = new char[bytes]; + boost::scoped_array data(new char[bytes]); qint64 pos = 0; - forever { - const qint64 bytes_read = source->read(data + pos, bytes - pos); - if (bytes_read == -1) { - delete[] data; + qint64 bytes_read; + do { + bytes_read = source->read(data.get() + pos, bytes - pos); + if (bytes_read == -1) return false; - } pos += bytes_read; - if (bytes_read == 0 || pos == bytes) - break; - } + } while (bytes_read > 0 && pos != bytes); pos = 0; - forever { - const qint64 bytes_written = destination->write(data + pos, bytes - pos); - if (bytes_written == -1) { - delete[] data; + qint64 bytes_written; + do { + bytes_written = destination->write(data.get() + pos, bytes - pos); + if (bytes_written == -1) return false; - } pos += bytes_written; - if (bytes_written == 0 || pos == bytes) - break; - } + } while (bytes_written > 0 && pos != bytes); - delete[] data; return true; }