QStringIterator: fix UB [1/2]: use has{Next,Previous}() more
Replace - pos > i with hasPrevious() - pos < e with hasNext() Everything is inline, so there's no difference in assembly, but less source code lines to fix later. Change-Id: I3f9cf2716c96b811b29b75fa20f88cc3b461771a Reviewed-by: Mate Barany <mate.barany@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit 34800d1f09447e921203561c0e4804c4f095136f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
ee37e7c69a
commit
9c0c998698
@ -85,7 +85,7 @@ public:
|
||||
Q_ASSERT_X(hasNext(), Q_FUNC_INFO, "iterator hasn't a next item");
|
||||
|
||||
if (Q_UNLIKELY((pos++)->isHighSurrogate())) {
|
||||
Q_ASSERT(pos < e && pos->isLowSurrogate());
|
||||
Q_ASSERT(hasNext() && pos->isLowSurrogate());
|
||||
++pos;
|
||||
}
|
||||
}
|
||||
@ -124,7 +124,7 @@ public:
|
||||
|
||||
const QChar cur = *pos++;
|
||||
if (Q_UNLIKELY(cur.isHighSurrogate())) {
|
||||
Q_ASSERT(pos < e && pos->isLowSurrogate());
|
||||
Q_ASSERT(hasNext() && pos->isLowSurrogate());
|
||||
return QChar::surrogateToUcs4(cur, *pos++);
|
||||
}
|
||||
return cur.unicode();
|
||||
@ -136,7 +136,7 @@ public:
|
||||
|
||||
const QChar uc = *pos++;
|
||||
if (Q_UNLIKELY(uc.isSurrogate())) {
|
||||
if (Q_LIKELY(uc.isHighSurrogate() && pos < e && pos->isLowSurrogate()))
|
||||
if (Q_LIKELY(uc.isHighSurrogate() && hasNext() && pos->isLowSurrogate()))
|
||||
return QChar::surrogateToUcs4(uc, *pos++);
|
||||
return invalidAs;
|
||||
}
|
||||
@ -167,7 +167,7 @@ public:
|
||||
Q_ASSERT_X(hasPrevious(), Q_FUNC_INFO, "iterator hasn't a previous item");
|
||||
|
||||
if (Q_UNLIKELY((--pos)->isLowSurrogate())) {
|
||||
Q_ASSERT(pos > i && pos[-1].isHighSurrogate());
|
||||
Q_ASSERT(hasPrevious() && pos[-1].isHighSurrogate());
|
||||
--pos;
|
||||
}
|
||||
}
|
||||
@ -205,7 +205,7 @@ public:
|
||||
|
||||
const QChar cur = *--pos;
|
||||
if (Q_UNLIKELY(cur.isLowSurrogate())) {
|
||||
Q_ASSERT(pos > i && pos[-1].isHighSurrogate());
|
||||
Q_ASSERT(hasPrevious() && pos[-1].isHighSurrogate());
|
||||
return QChar::surrogateToUcs4(*--pos, cur);
|
||||
}
|
||||
return cur.unicode();
|
||||
@ -217,7 +217,7 @@ public:
|
||||
|
||||
const QChar uc = *--pos;
|
||||
if (Q_UNLIKELY(uc.isSurrogate())) {
|
||||
if (Q_LIKELY(uc.isLowSurrogate() && pos > i && pos[-1].isHighSurrogate()))
|
||||
if (Q_LIKELY(uc.isLowSurrogate() && hasPrevious() && pos[-1].isHighSurrogate()))
|
||||
return QChar::surrogateToUcs4(*--pos, uc);
|
||||
return invalidAs;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user