From 4a97029ce71262395620b71633b309f3e6bb6f54 Mon Sep 17 00:00:00 2001 From: David Tardon Date: Wed, 15 Oct 2014 17:02:59 +0200 Subject: avoid out-of-bounds access when iterating code points Change-Id: I88290e5ccfd6ab250fe1526e452609e6de020dcd --- i18npool/source/breakiterator/xdictionary.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'i18npool') diff --git a/i18npool/source/breakiterator/xdictionary.cxx b/i18npool/source/breakiterator/xdictionary.cxx index b930f46d9840..567a2db1aced 100644 --- a/i18npool/source/breakiterator/xdictionary.cxx +++ b/i18npool/source/breakiterator/xdictionary.cxx @@ -414,11 +414,13 @@ Boundary xdictionary::nextWord(const OUString& rText, sal_Int32 anyPos, sal_Int1 { boundary = getWordBoundary(rText, anyPos, wordType, true); anyPos = boundary.endPos; - if (anyPos < rText.getLength()) { + const sal_Int32 nLen = rText.getLength(); + if (anyPos < nLen) { // looknig for the first non-whitespace character from anyPos sal_uInt32 ch = rText.iterateCodePoints(&anyPos, 1); - while (u_isWhitespace(ch)) ch=rText.iterateCodePoints(&anyPos, 1); - rText.iterateCodePoints(&anyPos, -1); + while (u_isWhitespace(ch) && (anyPos < nLen)) ch=rText.iterateCodePoints(&anyPos, 1); + if (anyPos > 0) + rText.iterateCodePoints(&anyPos, -1); } return getWordBoundary(rText, anyPos, wordType, true); -- cgit