compilerplugins/clang/flatten.cxx                       |    5 ++
 i18npool/source/breakiterator/breakiterator_unicode.cxx |   24 +++++-----
 i18npool/source/calendar/calendar_gregorian.cxx         |   35 ++++++++--------
 i18npool/source/calendar/calendar_hijri.cxx             |   31 +++++++-------
 i18npool/source/calendar/calendar_jewish.cxx            |   27 ++++++------
 i18npool/source/nativenumber/nativenumbersupplier.cxx   |   29 ++++++-------
 6 files changed, 80 insertions(+), 71 deletions(-)

New commits:
commit 32343bcbb786168df62f85a57e30c620c3d3bdb4
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Apr 7 19:59:47 2020 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Wed Apr 8 11:01:14 2020 +0200

    loplugin:flatten in i18npool
    
    and workaround a clang crash
    
    Change-Id: Ida94c8abb4b2e997d38a7f430e59f73aadf8fcc8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91844
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/compilerplugins/clang/flatten.cxx 
b/compilerplugins/clang/flatten.cxx
index 68baa742dcca..a084fabb9204 100644
--- a/compilerplugins/clang/flatten.cxx
+++ b/compilerplugins/clang/flatten.cxx
@@ -650,6 +650,11 @@ std::string Flatten::getSourceAsString(SourceRange range)
     char const *p1 = SM.getCharacterData( startLoc );
     char const *p2 = SM.getCharacterData( endLoc );
     p2 += Lexer::MeasureTokenLength( endLoc, SM, compiler.getLangOpts());
+    if (p2 < p1) {
+        // workaround clang weirdness, but don't return empty string
+        // in case it happens during code replacement
+        return "clang returned bad pointers";
+    }
     return std::string( p1, p2 - p1);
 }
 
diff --git a/i18npool/source/breakiterator/breakiterator_unicode.cxx 
b/i18npool/source/breakiterator/breakiterator_unicode.cxx
index 22d8a8b50568..b756fbbdbee2 100644
--- a/i18npool/source/breakiterator/breakiterator_unicode.cxx
+++ b/i18npool/source/breakiterator/breakiterator_unicode.cxx
@@ -307,23 +307,23 @@ void BreakIterator_Unicode::loadICUBreakIterator(const 
css::lang::Locale& rLocal
         bNewBreak=true;
     }
 
-    if (bNewBreak || icuBI->mpValue->maICUText.pData != rText.pData)
-    {
-        const UChar *pText = reinterpret_cast<const UChar *>(rText.getStr());
+    if (!(bNewBreak || icuBI->mpValue->maICUText.pData != rText.pData))
+        return;
 
-        status = U_ZERO_ERROR;
-        icuBI->mpValue->mpUt = utext_openUChars(icuBI->mpValue->mpUt, pText, 
rText.getLength(), &status);
+    const UChar *pText = reinterpret_cast<const UChar *>(rText.getStr());
 
-        if (!U_SUCCESS(status))
-            throw uno::RuntimeException();
+    status = U_ZERO_ERROR;
+    icuBI->mpValue->mpUt = utext_openUChars(icuBI->mpValue->mpUt, pText, 
rText.getLength(), &status);
 
-        icuBI->mpValue->mpBreakIterator->setText(icuBI->mpValue->mpUt, status);
+    if (!U_SUCCESS(status))
+        throw uno::RuntimeException();
 
-        if (!U_SUCCESS(status))
-            throw uno::RuntimeException();
+    icuBI->mpValue->mpBreakIterator->setText(icuBI->mpValue->mpUt, status);
 
-        icuBI->mpValue->maICUText = rText;
-    }
+    if (!U_SUCCESS(status))
+        throw uno::RuntimeException();
+
+    icuBI->mpValue->maICUText = rText;
 }
 
 sal_Int32 SAL_CALL BreakIterator_Unicode::nextCharacters( const OUString& Text,
diff --git a/i18npool/source/calendar/calendar_gregorian.cxx 
b/i18npool/source/calendar/calendar_gregorian.cxx
index a4eaf3dcde9f..b7ae49fbd96e 100644
--- a/i18npool/source/calendar/calendar_gregorian.cxx
+++ b/i18npool/source/calendar/calendar_gregorian.cxx
@@ -394,27 +394,28 @@ bool Calendar_gregorian::setTimeZone( const OUString& 
rTimeZone )
 // By using eraArray, it can take care Japanese and Taiwan ROC calendar.
 void Calendar_gregorian::mapFromGregorian()
 {
-    if (eraArray) {
-        sal_Int16 e, y, m, d;
+    if (!eraArray)
+        return;
 
-        e = fieldValue[CalendarFieldIndex::ERA];
-        y = fieldValue[CalendarFieldIndex::YEAR];
-        m = fieldValue[CalendarFieldIndex::MONTH] + 1;
-        d = fieldValue[CalendarFieldIndex::DAY_OF_MONTH];
+    sal_Int16 e, y, m, d;
 
-        // since the year is reversed for first era, it is reversed again here 
for Era compare.
-        if (e == 0)
-            y = 1 - y;
+    e = fieldValue[CalendarFieldIndex::ERA];
+    y = fieldValue[CalendarFieldIndex::YEAR];
+    m = fieldValue[CalendarFieldIndex::MONTH] + 1;
+    d = fieldValue[CalendarFieldIndex::DAY_OF_MONTH];
 
-        for (e = 0; eraArray[e].year; e++)
-            if ((y != eraArray[e].year) ? y < eraArray[e].year :
-                    (m != eraArray[e].month) ? m < eraArray[e].month : d < 
eraArray[e].day)
-                break;
+    // since the year is reversed for first era, it is reversed again here for 
Era compare.
+    if (e == 0)
+        y = 1 - y;
 
-        fieldValue[CalendarFieldIndex::ERA] = e;
-        fieldValue[CalendarFieldIndex::YEAR] =
-            sal::static_int_cast<sal_Int16>( (e == 0) ? (eraArray[0].year - y) 
: (y - eraArray[e-1].year + 1) );
-    }
+    for (e = 0; eraArray[e].year; e++)
+        if ((y != eraArray[e].year) ? y < eraArray[e].year :
+                (m != eraArray[e].month) ? m < eraArray[e].month : d < 
eraArray[e].day)
+            break;
+
+    fieldValue[CalendarFieldIndex::ERA] = e;
+    fieldValue[CalendarFieldIndex::YEAR] =
+        sal::static_int_cast<sal_Int16>( (e == 0) ? (eraArray[0].year - y) : 
(y - eraArray[e-1].year + 1) );
 }
 
 #define FIELDS  ((1 << CalendarFieldIndex::ERA) | (1 << 
CalendarFieldIndex::YEAR))
diff --git a/i18npool/source/calendar/calendar_hijri.cxx 
b/i18npool/source/calendar/calendar_hijri.cxx
index ce48dac0f127..dca8b95836fc 100644
--- a/i18npool/source/calendar/calendar_hijri.cxx
+++ b/i18npool/source/calendar/calendar_hijri.cxx
@@ -68,21 +68,22 @@ Calendar_hijri::Calendar_hijri()
 // map field value from hijri calendar to gregorian calendar
 void Calendar_hijri::mapToGregorian()
 {
-    if (fieldSet & FIELDS) {
-        sal_Int32 day = 
static_cast<sal_Int32>(fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH]);
-        sal_Int32 month = 
static_cast<sal_Int32>(fieldSetValue[CalendarFieldIndex::MONTH]) + 1;
-        sal_Int32 year = 
static_cast<sal_Int32>(fieldSetValue[CalendarFieldIndex::YEAR]);
-        if (fieldSetValue[CalendarFieldIndex::ERA] == 0)
-            year *= -1;
-
-        ToGregorian(&day, &month, &year);
-
-        fieldSetValue[CalendarFieldIndex::ERA] = year <= 0 ? 0 : 1;
-        fieldSetValue[CalendarFieldIndex::MONTH] = 
sal::static_int_cast<sal_Int16>(month - 1);
-        fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH] = 
static_cast<sal_Int16>(day);
-        fieldSetValue[CalendarFieldIndex::YEAR] = 
static_cast<sal_Int16>(abs(year));
-        fieldSet |= FIELDS;
-    }
+    if (!(fieldSet & FIELDS))
+        return;
+
+    sal_Int32 day = 
static_cast<sal_Int32>(fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH]);
+    sal_Int32 month = 
static_cast<sal_Int32>(fieldSetValue[CalendarFieldIndex::MONTH]) + 1;
+    sal_Int32 year = 
static_cast<sal_Int32>(fieldSetValue[CalendarFieldIndex::YEAR]);
+    if (fieldSetValue[CalendarFieldIndex::ERA] == 0)
+        year *= -1;
+
+    ToGregorian(&day, &month, &year);
+
+    fieldSetValue[CalendarFieldIndex::ERA] = year <= 0 ? 0 : 1;
+    fieldSetValue[CalendarFieldIndex::MONTH] = 
sal::static_int_cast<sal_Int16>(month - 1);
+    fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH] = 
static_cast<sal_Int16>(day);
+    fieldSetValue[CalendarFieldIndex::YEAR] = 
static_cast<sal_Int16>(abs(year));
+    fieldSet |= FIELDS;
 }
 
 // map field value from gregorian calendar to hijri calendar
diff --git a/i18npool/source/calendar/calendar_jewish.cxx 
b/i18npool/source/calendar/calendar_jewish.cxx
index ee35c5d90cf9..ab5a32a221d8 100644
--- a/i18npool/source/calendar/calendar_jewish.cxx
+++ b/i18npool/source/calendar/calendar_jewish.cxx
@@ -272,19 +272,20 @@ void Calendar_jewish::mapFromGregorian()
 // map field value from other calendar to gregorian calendar, it should be 
implemented.
 void Calendar_jewish::mapToGregorian()
 {
-    if (fieldSet & FIELDS) {
-        sal_Int16 y = fieldSetValue[CalendarFieldIndex::YEAR];
-        if (fieldSetValue[CalendarFieldIndex::ERA] == 0)
-            y = 1 - y;
-        HebrewDate Temp(fieldSetValue[CalendarFieldIndex::MONTH] + 1, 
fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH], y);
-        GregorianDate gd(Temp.GetAbsoluteDate());
-
-        fieldSetValue[CalendarFieldIndex::ERA] = gd.GetYear() <= 0 ? 0 : 1;
-        fieldSetValue[CalendarFieldIndex::MONTH] = 
sal::static_int_cast<sal_Int16>( gd.GetMonth() - 1 );
-        fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH] = 
static_cast<sal_Int16>(gd.GetDay());
-        fieldSetValue[CalendarFieldIndex::YEAR] = 
static_cast<sal_Int16>(gd.GetYear() <= 0 ? 1 - gd.GetYear() : gd.GetYear());
-        fieldSet |= FIELDS;
-    }
+    if (!(fieldSet & FIELDS))
+        return;
+
+    sal_Int16 y = fieldSetValue[CalendarFieldIndex::YEAR];
+    if (fieldSetValue[CalendarFieldIndex::ERA] == 0)
+        y = 1 - y;
+    HebrewDate Temp(fieldSetValue[CalendarFieldIndex::MONTH] + 1, 
fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH], y);
+    GregorianDate gd(Temp.GetAbsoluteDate());
+
+    fieldSetValue[CalendarFieldIndex::ERA] = gd.GetYear() <= 0 ? 0 : 1;
+    fieldSetValue[CalendarFieldIndex::MONTH] = 
sal::static_int_cast<sal_Int16>( gd.GetMonth() - 1 );
+    fieldSetValue[CalendarFieldIndex::DAY_OF_MONTH] = 
static_cast<sal_Int16>(gd.GetDay());
+    fieldSetValue[CalendarFieldIndex::YEAR] = 
static_cast<sal_Int16>(gd.GetYear() <= 0 ? 1 - gd.GetYear() : gd.GetYear());
+    fieldSet |= FIELDS;
 }
 
 // Methods in XExtendedCalendar
diff --git a/i18npool/source/nativenumber/nativenumbersupplier.cxx 
b/i18npool/source/nativenumber/nativenumbersupplier.cxx
index ff521145045e..8579c51035d8 100644
--- a/i18npool/source/nativenumber/nativenumbersupplier.cxx
+++ b/i18npool/source/nativenumber/nativenumbersupplier.cxx
@@ -1168,21 +1168,22 @@ static void makeCyrillicNumber(sal_Int64 value, 
OUStringBuffer& output, bool add
         }
     }
 
-    if (addTitlo) {
-        if (output.getLength() == 1) {
+    if (!addTitlo)
+        return;
+
+    if (output.getLength() == 1) {
+        output.append(cyrillicTitlo);
+    } else if (output.getLength() == 2) {
+        if (value > 800 && value < 900) {
             output.append(cyrillicTitlo);
-        } else if (output.getLength() == 2) {
-            if (value > 800 && value < 900) {
-                output.append(cyrillicTitlo);
-            } else {
-                output.insert(1, cyrillicTitlo);
-            }
-        } else if (output.getLength() > 2) {
-            if (output.indexOf(" ") == output.getLength() - 2) {
-                output.append(cyrillicTitlo);
-            } else {
-                output.insert(output.getLength() - 1, cyrillicTitlo);
-            }
+        } else {
+            output.insert(1, cyrillicTitlo);
+        }
+    } else if (output.getLength() > 2) {
+        if (output.indexOf(" ") == output.getLength() - 2) {
+            output.append(cyrillicTitlo);
+        } else {
+            output.insert(output.getLength() - 1, cyrillicTitlo);
         }
     }
 }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to