From 8a4099a0aa86969744d1258244abf2b8d3e8ed26 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Sun, 4 Jan 2015 22:53:41 +0100 Subject: [PATCH] QIsciiCodec: add an assert to silence Coverity Coverity (not rightfully) complains that the code is using "iscii", a uchar obtained by looking up into a table, as an index into the "uni_to_iscii_pairs" array. Since the array is only 18 elements long, there's the theoretic risk of accessing it past its end. However, the lookup of "iscii" never returns values that may actually go out of bounds. Coverity may be smart enough to see the values that "iscii" can get and not raise the warning, but since it does, make the code more robust and add an assert. Task-number: QTBUG-43642 Change-Id: Id75ca105758b343102ca94137d0379c10e55581a Reviewed-by: Olivier Goffart --- src/corelib/codecs/qisciicodec.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/corelib/codecs/qisciicodec.cpp b/src/corelib/codecs/qisciicodec.cpp index e0c33aaa50..bd3b31667c 100644 --- a/src/corelib/codecs/qisciicodec.cpp +++ b/src/corelib/codecs/qisciicodec.cpp @@ -212,6 +212,7 @@ QByteArray QIsciiCodec::convertFromUnicode(const QChar *uc, int len, ConverterSt if (iscii > 0x80) { *ch++ = iscii; } else if (iscii) { + Q_ASSERT((2 * iscii) < (sizeof(uni_to_iscii_pairs) / sizeof(uni_to_iscii_pairs[0]))); const uchar *pair = uni_to_iscii_pairs + 2*iscii; *ch++ = *pair++; *ch++ = *pair++;