From 0696566b1e19c8178e00c0d14f185935e17d9e8b Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 20 Jul 2016 16:49:33 +0200 Subject: Windows: Fix truncation in QFSFileEnginePrivate::nativeWrite() The number of bytes to write was converted to a 32bit unsigned value, causing losses. Change the type to qint64 and adapt the code determining the block size. Task-number: QTBUG-54870 Change-Id: I294da5bfe97c7e60f67228399e1244a1aba4c89c Reviewed-by: Maurice Kalinowski --- src/corelib/io/qfsfileengine_win.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/corelib/io/qfsfileengine_win.cpp') diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 689251a6c7..391fbcc519 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -423,15 +423,13 @@ qint64 QFSFileEnginePrivate::nativeWrite(const char *data, qint64 len) if (fileHandle == INVALID_HANDLE_VALUE) return -1; - qint64 bytesToWrite = DWORD(len); // <- lossy + qint64 bytesToWrite = len; // Writing on Windows fails with ERROR_NO_SYSTEM_RESOURCES when // the chunks are too large, so we limit the block size to 32MB. - static const DWORD maxBlockSize = 32 * 1024 * 1024; - + const DWORD blockSize = DWORD(qMin(bytesToWrite, qint64(32 * 1024 * 1024))); qint64 totalWritten = 0; do { - DWORD blockSize = qMin(bytesToWrite, maxBlockSize); DWORD bytesWritten; if (!WriteFile(fileHandle, data + totalWritten, blockSize, &bytesWritten, NULL)) { if (totalWritten == 0) { -- cgit v1.2.3