diff options
author | João Abecasis <joao@abecasis.name> | 2009-04-23 09:44:00 (GMT) |
---|---|---|
committer | João Abecasis <joao@abecasis.name> | 2009-04-23 13:28:12 (GMT) |
commit | eb48c652475a11d32e8ce5fd7d42cea827656f10 (patch) | |
tree | 8fd7c10a147d0d8013bf6d3b307e4b2f68e7d983 /src/corelib | |
parent | d913582c270f9f1039a3a788980360aadf39b286 (diff) | |
download | Qt-eb48c652475a11d32e8ce5fd7d42cea827656f10.zip Qt-eb48c652475a11d32e8ce5fd7d42cea827656f10.tar.gz Qt-eb48c652475a11d32e8ce5fd7d42cea827656f10.tar.bz2 |
Fixes for QByteArrayMatcher
Copy constructor and assignment operator lose data: pointer to content
and the length of content also need to be copied over.
QByteArrayMatcher::pattern() would return a null byte array if instance
was initialized with c-string.
Changed default constructor to explicitly initialize pattern length to
zero.
The bug in the assignment operator is a regression against 4.4.3.
Task-number: 251958
Reviewed-by: MariusSO
Reviewed-by: paul
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qbytearraymatcher.cpp | 3 | ||||
-rw-r--r-- | src/corelib/tools/qbytearraymatcher.h | 7 |
2 files changed, 8 insertions, 2 deletions
diff --git a/src/corelib/tools/qbytearraymatcher.cpp b/src/corelib/tools/qbytearraymatcher.cpp index cd4cf90..211d190 100644 --- a/src/corelib/tools/qbytearraymatcher.cpp +++ b/src/corelib/tools/qbytearraymatcher.cpp @@ -120,6 +120,7 @@ QByteArrayMatcher::QByteArrayMatcher() : d(0) { p.p = 0; + p.l = 0; qMemSet(p.q_skiptable, 0, sizeof(p.q_skiptable)); } @@ -170,7 +171,7 @@ QByteArrayMatcher::~QByteArrayMatcher() QByteArrayMatcher &QByteArrayMatcher::operator=(const QByteArrayMatcher &other) { q_pattern = other.q_pattern; - qMemCopy(p.q_skiptable, other.p.q_skiptable, sizeof(p.q_skiptable)); + qMemCopy(&p, &other.p, sizeof(p)); return *this; } diff --git a/src/corelib/tools/qbytearraymatcher.h b/src/corelib/tools/qbytearraymatcher.h index d7f2366..633e92c 100644 --- a/src/corelib/tools/qbytearraymatcher.h +++ b/src/corelib/tools/qbytearraymatcher.h @@ -67,7 +67,12 @@ public: int indexIn(const QByteArray &ba, int from = 0) const; int indexIn(const char *str, int len, int from = 0) const; - inline QByteArray pattern() const { return q_pattern; } + inline QByteArray pattern() const + { + if (q_pattern.isNull()) + return QByteArray((const char*)p.p, p.l); + return q_pattern; + } private: QByteArrayMatcherPrivate *d; |