summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2019-03-04 10:32:08 +0100
committerAndy Shaw <andy.shaw@qt.io>2019-03-05 08:44:56 +0000
commit28d0b987b743751ea2e8f96fc42b1c792c9e0561 (patch)
tree817cbb80fe7f1925690b8c60a76669fcb936fed6 /src
parent7789b77458e339320644cfc2822b008dfae9a616 (diff)
Handle the situation where QTemporaryFile::open() fails
If open() fails then we should make sure we do not try to write to it and just return 0 in that case. Change-Id: I2980b65766b322efed6708fb10cc27567174dc37 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qtemporaryfile.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/corelib/io/qtemporaryfile.cpp b/src/corelib/io/qtemporaryfile.cpp
index 7e3be9ef36..35bb465a04 100644
--- a/src/corelib/io/qtemporaryfile.cpp
+++ b/src/corelib/io/qtemporaryfile.cpp
@@ -912,16 +912,20 @@ QTemporaryFile *QTemporaryFile::createNativeFile(QFile &file)
file.open(QIODevice::ReadOnly);
//dump data
QTemporaryFile *ret = new QTemporaryFile;
- ret->open();
- file.seek(0);
- char buffer[1024];
- while(true) {
- qint64 len = file.read(buffer, 1024);
- if(len < 1)
- break;
- ret->write(buffer, len);
+ if (ret->open()) {
+ file.seek(0);
+ char buffer[1024];
+ while (true) {
+ qint64 len = file.read(buffer, 1024);
+ if (len < 1)
+ break;
+ ret->write(buffer, len);
+ }
+ ret->seek(0);
+ } else {
+ delete ret;
+ ret = nullptr;
}
- ret->seek(0);
//restore
if(wasOpen)
file.seek(old_off);