unotools/source/i18n/charclass.cxx |   19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

New commits:
commit c0d09eb46665a0b2ab86f263cc95662f406d83d2
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Tue Sep 13 11:04:20 2022 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Tue Sep 13 12:37:12 2022 +0200

    Empty string has no characters of any type
    
    Change-Id: Id7244032d52360d2b0ea57fba023dff162a29d95
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139831
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Eike Rathke <er...@redhat.com>

diff --git a/unotools/source/i18n/charclass.cxx 
b/unotools/source/i18n/charclass.cxx
index 4573687c4d29..be3a9f4f0ee0 100644
--- a/unotools/source/i18n/charclass.cxx
+++ b/unotools/source/i18n/charclass.cxx
@@ -132,6 +132,9 @@ bool CharClass::isLetter( const OUString& rStr, sal_Int32 
nPos ) const
 
 bool CharClass::isLetter( const OUString& rStr ) const
 {
+    if (rStr.isEmpty())
+        return false;
+
     try
     {
         sal_Int32 nPos = 0;
@@ -170,6 +173,9 @@ bool CharClass::isDigit( const OUString& rStr, sal_Int32 
nPos ) const
 
 bool CharClass::isNumeric( const OUString& rStr ) const
 {
+    if (rStr.isEmpty())
+        return false;
+
     try
     {
         sal_Int32 nPos = 0;
@@ -226,6 +232,9 @@ bool CharClass::isLetterNumeric( const OUString& rStr, 
sal_Int32 nPos ) const
 
 bool CharClass::isLetterNumeric( const OUString& rStr ) const
 {
+    if (rStr.isEmpty())
+        return false;
+
     try
     {
         sal_Int32 nPos = 0;
@@ -264,10 +273,16 @@ bool CharClass::isUpper( const OUString& rStr, sal_Int32 
nPos ) const
 
 bool CharClass::isUpper( const OUString& rStr, sal_Int32 nPos, sal_Int32 
nCount ) const
 {
+    if (rStr.isEmpty())
+        return false;
+
+    assert(nPos >= 0 && nPos < rStr.getLength() && nCount > 0);
+    if (nPos < 0 || nPos >= rStr.getLength() || nCount == 0)
+        return false;
+
     try
     {
-        assert(nPos >= 0 && nCount >= 0);
-        sal_Int32 nLen = std::min( nPos + nCount, rStr.getLength());
+        const sal_Int32 nLen = std::min( nPos + nCount, rStr.getLength());
         while (nPos < nLen)
         {
             if (!isUpper( rStr, nPos))

Reply via email to