diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-02-15 21:21:48 -0800 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-09 23:57:33 +0200 |
commit | df70d5ad80b465e284a467bb4d327a617ee17552 (patch) | |
tree | 6d8567cb81ed5b4470c989e41ec3167a3b2d47ce /src/testlib/qtestcase.cpp | |
parent | 918f20ee476d0cc8a4426c1abf4f44612afe13e1 (diff) |
Limit the QString pretty outputs to 256 characters
Change-Id: I88e71e517827af7d82e3a47d88d40787051ed827
Reviewed-by: Sergio Ahumada <sahumada@blackberry.com>
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r-- | src/testlib/qtestcase.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index cc58b51743..ffcc7abbfe 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -2143,18 +2143,26 @@ char *toHexRepresentation(const char *ba, int length) char *toPrettyUnicode(const ushort *p, int length) { // keep it simple for the vast majority of cases - QScopedArrayPointer<char> buffer(new char[length * 6 + 3]); + bool trimmed = false; + QScopedArrayPointer<char> buffer(new char[256]); const ushort *end = p + length; char *dst = buffer.data(); *dst++ = '"'; for ( ; p != end; ++p) { + if (dst - buffer.data() > 245) { + // plus the the quote, the three dots and NUL, it's 250, 251 or 255 + trimmed = true; + break; + } + if (*p < 0x7f && *p >= 0x20 && *p != '\\') { *dst++ = *p; continue; } // write as an escape sequence + // this means we may advance dst to buffer.data() + 246 or 250 *dst++ = '\\'; switch (*p) { case 0x22: @@ -2186,6 +2194,11 @@ char *toPrettyUnicode(const ushort *p, int length) } *dst++ = '"'; + if (trimmed) { + *dst++ = '.'; + *dst++ = '.'; + *dst++ = '.'; + } *dst++ = '\0'; return buffer.take(); } |