[poppler] qt5/src qt6/src

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri May 12 09:37:46 UTC 2023


 qt5/src/poppler-embeddedfile.cc |   11 ++---------
 qt6/src/poppler-embeddedfile.cc |   14 ++------------
 2 files changed, 4 insertions(+), 21 deletions(-)

New commits:
commit aefd09f9eb69b91ae2cae0351280aaa66742dd84
Author: Sune Vuorela <sune at vuorela.dk>
Date:   Thu May 11 16:43:41 2023 +0200

    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.

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


More information about the poppler mailing list