From 6d87a01f2d3108bbee5b9995f20edfc26a01cd57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Abecasis?= Date: Mon, 27 Jul 2009 17:12:50 +0200 Subject: Always check the file handle before attempting to map the file Reviewed-by: Maurice Kalinowski --- src/corelib/io/qfsfileengine_win.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 2d4fe0e..2fc9670 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -1927,8 +1927,9 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, #ifndef Q_OS_WINCE if (handle == INVALID_HANDLE_VALUE && fh) handle = (HANDLE)_get_osfhandle(QT_FILENO(fh)); -#else - #ifdef Q_USE_DEPRECATED_MAP_API +#endif + +#ifdef Q_USE_DEPRECATED_MAP_API if (fileMapHandle == INVALID_HANDLE_VALUE) { nativeClose(); fileMapHandle = CreateFileForMapping((const wchar_t*)nativeFilePath.constData(), @@ -1940,11 +1941,13 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size, NULL); } handle = fileMapHandle; - #endif - if (handle == INVALID_HANDLE_VALUE && fh) - return 0; #endif + if (handle == INVALID_HANDLE_VALUE) { + q->setError(QFile::UnspecifiedError, QLatin1String("No handle on file")); + return 0; + } + // first create the file mapping handle DWORD protection = (openMode & QIODevice::WriteOnly) ? PAGE_READWRITE : PAGE_READONLY; HANDLE mapHandle = ::CreateFileMapping(handle, 0, protection, 0, 0, 0); -- cgit v0.12