Commit c0a3a0ad authored by Daniel Kahn Gillmor's avatar Daniel Kahn Gillmor

Fix GooString using upstream patch (Closes: #924029)

parent 0153b6ab
From 8f158da92c53ae16a368f844965f57ba8ffed77d Mon Sep 17 00:00:00 2001
From: Adam Reichold <adam.reichold@t-online.de>
Date: Fri, 16 Nov 2018 21:36:33 +0100
Subject: [PATCH] Make GooString constructible and assignable from null
pointers again since some of the code expects it.
---
goo/GooString.h | 12 ++++++------
qt5/tests/check_goostring.cpp | 37 +++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 6 deletions(-)
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -60,7 +60,7 @@
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 @@
// 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.
--- a/qt5/tests/check_goostring.cpp
+++ b/qt5/tests/check_goostring.cpp
@@ -11,6 +11,7 @@
void testInsertData();
void testInsert();
void testFormat();
+ void testFromNullptr();
};
void TestGooString::testInsertData_data()
@@ -122,6 +123,42 @@
}
}
+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"
glib-Don-t-create-PopplerInputStream-with-length-0.patch glib-Don-t-create-PopplerInputStream-with-length-0.patch
page-ustring.patch page-ustring.patch
#qt-visibility.diff #qt-visibility.diff
Make-GooString-constructible-and-assignable-from-nul.patch
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment