summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSune Vuorela <sune@vuorela.dk>2023-05-11 16:43:41 +0200
committerSune Vuorela <sune@vuorela.dk>2023-05-11 16:48:10 +0200
commitaefd09f9eb69b91ae2cae0351280aaa66742dd84 (patch)
tree1fdb0a6d06feeb7630a9f06bd6e366f82aa9c45e
parent47856547b9b56c037049e48453f9ae65aa266a26 (diff)
Convert embedded files to bytearray a bit smarter
The current behavior also triggers a runtime warning per byte: "Using QByteRef with an index pointing outside the valid range of a QByteArray. The corresponding behavior is deprecated, and will be changed in a future version of Qt." This will keep an extra copy of the data around during convertion, but that's probably okay.
-rw-r--r--qt5/src/poppler-embeddedfile.cc11
-rw-r--r--qt6/src/poppler-embeddedfile.cc14
2 files changed, 4 insertions, 21 deletions
diff --git a/qt5/src/poppler-embeddedfile.cc b/qt5/src/poppler-embeddedfile.cc
index bab8d73f..9fe62c77 100644
--- a/qt5/src/poppler-embeddedfile.cc
+++ b/qt5/src/poppler-embeddedfile.cc
@@ -104,15 +104,8 @@ QByteArray EmbeddedFile::data()
}
stream->reset();
- int dataLen = 0;
- QByteArray fileArray;
- int i;
- while ((i = stream->getChar()) != EOF) {
- fileArray[dataLen] = (char)i;
- ++dataLen;
- }
- fileArray.resize(dataLen);
- return fileArray;
+ auto data = stream->toUnsignedChars();
+ return QByteArray(reinterpret_cast<const char *>(data.data()), data.size());
}
bool EmbeddedFile::isValid() const
diff --git a/qt6/src/poppler-embeddedfile.cc b/qt6/src/poppler-embeddedfile.cc
index 1b8a7a1c..42bfc6a4 100644
--- a/qt6/src/poppler-embeddedfile.cc
+++ b/qt6/src/poppler-embeddedfile.cc
@@ -104,18 +104,8 @@ QByteArray EmbeddedFile::data()
}
stream->reset();
- int dataLen = 0;
- QByteArray fileArray;
- int i;
- while ((i = stream->getChar()) != EOF) {
- if (dataLen >= fileArray.size()) {
- fileArray.resize(dataLen + 32768);
- }
- fileArray[dataLen] = (char)i;
- ++dataLen;
- }
- fileArray.resize(dataLen);
- return fileArray;
+ auto data = stream->toUnsignedChars();
+ return QByteArray(reinterpret_cast<const char *>(data.data()), data.size());
}
bool EmbeddedFile::isValid() const