[poppler] goo/GooString.h qt5/tests

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Nov 16 22:06:36 UTC 2018


 goo/GooString.h               |   12 ++++++------
 qt5/tests/check_goostring.cpp |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 6 deletions(-)

New commits:
commit 8f158da92c53ae16a368f844965f57ba8ffed77d
Author: Adam Reichold <adam.reichold at t-online.de>
Date:   Fri Nov 16 21:36:33 2018 +0100

    Make GooString constructible and assignable from null pointers again since some of the code expects it.

diff --git a/goo/GooString.h b/goo/GooString.h
index e7cc9ce7..5d0986f2 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -60,7 +60,7 @@ public:
   GooString& operator=(const GooString &other) = delete;
 
   // Create a string from a C string.
-  explicit GooString(const char *sA) : std::string(sA) {}
+  explicit GooString(const char *sA) : std::string(sA ? sA : "") {}
 
   // Zero-cost conversion from and to std::string
   explicit GooString(const std::string& str) : std::string(str) {}
@@ -70,18 +70,18 @@ public:
 
   // Create a string from <lengthA> chars at <sA>.  This string
   // can contain null characters.
-  GooString(const char *sA, int lengthA) : std::string(sA, lengthA) {}
+  GooString(const char *sA, int lengthA) : std::string(sA ? sA : "", sA ? lengthA : 0) {}
 
   // Create a string from <lengthA> chars at <idx> in <str>.
   GooString(const GooString *str, int idx, int lengthA) : std::string(*str, idx, lengthA) {}
 
   // Set content of a string to <newStr>.
-  GooString* Set(const GooString *newStr) { assign(*newStr); return this; }
-  GooString* Set(const char *newStr) { assign(newStr); return this; }
-  GooString* Set(const char *newStr, int newLen) { assign(newStr, newLen); return this; }
+  GooString* Set(const GooString *newStr) { assign(newStr ? static_cast<const std::string&>(*newStr) : std::string{}); return this; }
+  GooString* Set(const char *newStr) { assign(newStr ? newStr : ""); return this; }
+  GooString* Set(const char *newStr, int newLen) { assign(newStr ? newStr : "", newStr ? newLen : 0); return this; }
 
   // Copy a string.
-  explicit GooString(const GooString *str) : std::string(*str) {}
+  explicit GooString(const GooString *str) : std::string(str ? static_cast<const std::string&>(*str) : std::string{}) {}
   GooString *copy() const { return new GooString(this); }
 
   // Concatenate two strings.
diff --git a/qt5/tests/check_goostring.cpp b/qt5/tests/check_goostring.cpp
index ed3ea535..3bdfcf77 100644
--- a/qt5/tests/check_goostring.cpp
+++ b/qt5/tests/check_goostring.cpp
@@ -13,6 +13,7 @@ private slots:
     void testInsertData();
     void testInsert();
     void testFormat();
+    void testFromNullptr();
 };
 
 void TestGooString::testInsertData_data()
@@ -124,6 +125,42 @@ void TestGooString::testFormat()
     }
 }
 
+void TestGooString::testFromNullptr()
+{
+  {
+    GooString str{static_cast<const GooString*>(nullptr)};
+    QCOMPARE(str.getLength(), 0);
+  }
+
+  {
+    GooString str;
+    str.Set(static_cast<const GooString*>(nullptr));
+    QCOMPARE(str.getLength(), 0);
+  }
+
+  {
+    GooString str{static_cast<const char*>(nullptr)};
+    QCOMPARE(str.getLength(), 0);
+  }
+
+  {
+    GooString str{static_cast<const char*>(nullptr), 0};
+    QCOMPARE(str.getLength(), 0);
+  }
+
+  {
+    GooString str;
+    str.Set(static_cast<const char*>(nullptr));
+    QCOMPARE(str.getLength(), 0);
+  }
+
+  {
+    GooString str;
+    str.Set(static_cast<const char*>(nullptr), 0);
+    QCOMPARE(str.getLength(), 0);
+  }
+}
+
 QTEST_GUILESS_MAIN(TestGooString)
 #include "check_goostring.moc"
 


More information about the poppler mailing list