[Libreoffice-commits] core.git: sal/osl sal/rtl

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Apr 2 18:06:52 UTC 2020


 sal/osl/all/log.cxx              |   57 ++++++++--------
 sal/osl/unx/file_path_helper.cxx |   26 +++----
 sal/osl/unx/process.cxx          |   54 +++++++--------
 sal/osl/unx/profile.cxx          |  114 ++++++++++++++++----------------
 sal/osl/unx/signal.cxx           |   66 +++++++++---------
 sal/rtl/bootstrap.cxx            |   42 ++++++------
 sal/rtl/cipher.cxx               |   40 +++++------
 sal/rtl/cmdargs.cxx              |   46 ++++++-------
 sal/rtl/strbuf.cxx               |   84 ++++++++++++------------
 sal/rtl/ustrbuf.cxx              |  136 +++++++++++++++++++--------------------
 10 files changed, 333 insertions(+), 332 deletions(-)

New commits:
commit 4acb0e7f05fa7fe05f990786e0483e20962af1d9
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Apr 2 10:58:02 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Apr 2 20:06:15 2020 +0200

    loplugin:flatten in sal
    
    Change-Id: Icc30c79d599486203c8f763cd5ff43059f0bb910
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91556
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx
index 5a6ffdff9110..ed663076b8d2 100644
--- a/sal/osl/all/log.cxx
+++ b/sal/osl/all/log.cxx
@@ -228,23 +228,23 @@ void maybeOutputTimestamp(std::ostringstream &s) {
                  static_cast<unsigned>(dateTime.NanoSeconds / 1000000));
         s << ts << '.' << milliSecs << ':';
     }
-    if (outputRelativeTimer)
+    if (!outputRelativeTimer)
+        return;
+
+    TimeValue now;
+    osl_getSystemTime(&now);
+    int seconds = now.Seconds - aStartTime.aTime.Seconds;
+    int milliSeconds;
+    if (now.Nanosec < aStartTime.aTime.Nanosec)
     {
-        TimeValue now;
-        osl_getSystemTime(&now);
-        int seconds = now.Seconds - aStartTime.aTime.Seconds;
-        int milliSeconds;
-        if (now.Nanosec < aStartTime.aTime.Nanosec)
-        {
-            seconds--;
-            milliSeconds = 1000 - (aStartTime.aTime.Nanosec - now.Nanosec) / 1000000;
-        }
-        else
-            milliSeconds = (now.Nanosec - aStartTime.aTime.Nanosec) / 1000000;
-        char relativeTimestamp[100];
-        snprintf(relativeTimestamp, sizeof(relativeTimestamp), "%d.%03d", seconds, milliSeconds);
-        s << relativeTimestamp << ':';
+        seconds--;
+        milliSeconds = 1000 - (aStartTime.aTime.Nanosec - now.Nanosec) / 1000000;
     }
+    else
+        milliSeconds = (now.Nanosec - aStartTime.aTime.Nanosec) / 1000000;
+    char relativeTimestamp[100];
+    snprintf(relativeTimestamp, sizeof(relativeTimestamp), "%d.%03d", seconds, milliSeconds);
+    s << relativeTimestamp << ':';
 }
 
 #endif
@@ -344,20 +344,21 @@ void sal_detail_logFormat(
     sal_detail_LogLevel level, char const * area, char const * where,
     char const * format, ...)
 {
-    if (sal_detail_log_report(level, area)) {
-        std::va_list args;
-        va_start(args, format);
-        char buf[1024];
-        int const len = sizeof buf - RTL_CONSTASCII_LENGTH("...");
-        int n = vsnprintf(buf, len, format, args);
-        if (n < 0) {
-            std::strcpy(buf, "???");
-        } else if (n >= len) {
-            std::strcpy(buf + len - 1, "...");
-        }
-        sal_detail_log(level, area, where, buf, 0);
-        va_end(args);
+    if (!sal_detail_log_report(level, area))
+        return;
+
+    std::va_list args;
+    va_start(args, format);
+    char buf[1024];
+    int const len = sizeof buf - RTL_CONSTASCII_LENGTH("...");
+    int n = vsnprintf(buf, len, format, args);
+    if (n < 0) {
+        std::strcpy(buf, "???");
+    } else if (n >= len) {
+        std::strcpy(buf + len - 1, "...");
     }
+    sal_detail_log(level, area, where, buf, 0);
+    va_end(args);
 }
 
 sal_Bool sal_detail_log_report(sal_detail_LogLevel level, char const * area) {
diff --git a/sal/osl/unx/file_path_helper.cxx b/sal/osl/unx/file_path_helper.cxx
index a0ef13f9503d..080a99c09928 100644
--- a/sal/osl/unx/file_path_helper.cxx
+++ b/sal/osl/unx/file_path_helper.cxx
@@ -35,21 +35,21 @@ const sal_Unicode FPH_CHAR_COLON          = ':';
 void osl_systemPathRemoveSeparator(rtl_String* pstrPath)
 {
     OSL_PRECOND(nullptr != pstrPath, "osl_systemPathRemoveSeparator: Invalid parameter");
-    if (pstrPath != nullptr)
-    {
-        // maybe there are more than one separator at end
-        // so we run in a loop
-        while ((pstrPath->length > 1) && (pstrPath->buffer[pstrPath->length - 1] == FPH_CHAR_PATH_SEPARATOR))
-        {
-            pstrPath->length--;
-            pstrPath->buffer[pstrPath->length] = '\0';
-        }
+    if (pstrPath == nullptr)
+        return;
 
-        SAL_WARN_IF( !((0 == pstrPath->length) || (1 == pstrPath->length) ||
-                     (pstrPath->length > 1 && pstrPath->buffer[pstrPath->length - 1] != FPH_CHAR_PATH_SEPARATOR)),
-                     "sal.osl",
-                     "osl_systemPathRemoveSeparator: Post condition failed");
+    // maybe there are more than one separator at end
+    // so we run in a loop
+    while ((pstrPath->length > 1) && (pstrPath->buffer[pstrPath->length - 1] == FPH_CHAR_PATH_SEPARATOR))
+    {
+        pstrPath->length--;
+        pstrPath->buffer[pstrPath->length] = '\0';
     }
+
+    SAL_WARN_IF( !((0 == pstrPath->length) || (1 == pstrPath->length) ||
+                 (pstrPath->length > 1 && pstrPath->buffer[pstrPath->length - 1] != FPH_CHAR_PATH_SEPARATOR)),
+                 "sal.osl",
+                 "osl_systemPathRemoveSeparator: Post condition failed");
 }
 
 namespace {
diff --git a/sal/osl/unx/process.cxx b/sal/osl/unx/process.cxx
index f2746bda2b18..39db4936fa3f 100644
--- a/sal/osl/unx/process.cxx
+++ b/sal/osl/unx/process.cxx
@@ -747,44 +747,44 @@ oslProcess SAL_CALL osl_getProcess(oslProcessIdentifier Ident)
 
 void SAL_CALL osl_freeProcessHandle(oslProcess Process)
 {
-    if (Process != nullptr)
-    {
-        oslProcessImpl *pChild, *pPrev = nullptr;
+    if (Process == nullptr)
+        return;
 
-        OSL_ASSERT(ChildListMutex != nullptr);
+    oslProcessImpl *pChild, *pPrev = nullptr;
 
-        if ( ChildListMutex == nullptr )
-        {
-            return;
-        }
+    OSL_ASSERT(ChildListMutex != nullptr);
 
-        osl_acquireMutex(ChildListMutex);
+    if ( ChildListMutex == nullptr )
+    {
+        return;
+    }
 
-        pChild = ChildList;
+    osl_acquireMutex(ChildListMutex);
 
-        /* remove process from child list */
-        while (pChild != nullptr)
-        {
-            if (pChild == static_cast<oslProcessImpl*>(Process))
-            {
-                if (pPrev != nullptr)
-                    pPrev->m_pnext = pChild->m_pnext;
-                else
-                    ChildList = pChild->m_pnext;
+    pChild = ChildList;
 
-                break;
-            }
+    /* remove process from child list */
+    while (pChild != nullptr)
+    {
+        if (pChild == static_cast<oslProcessImpl*>(Process))
+        {
+            if (pPrev != nullptr)
+                pPrev->m_pnext = pChild->m_pnext;
+            else
+                ChildList = pChild->m_pnext;
 
-            pPrev  = pChild;
-            pChild = pChild->m_pnext;
+            break;
         }
 
-        osl_releaseMutex(ChildListMutex);
+        pPrev  = pChild;
+        pChild = pChild->m_pnext;
+    }
 
-        osl_destroyCondition(static_cast<oslProcessImpl*>(Process)->m_terminated);
+    osl_releaseMutex(ChildListMutex);
 
-        free(Process);
-    }
+    osl_destroyCondition(static_cast<oslProcessImpl*>(Process)->m_terminated);
+
+    free(Process);
 }
 
 #if defined(LINUX)
diff --git a/sal/osl/unx/profile.cxx b/sal/osl/unx/profile.cxx
index e2cca48ab8c6..edb76019ff5d 100644
--- a/sal/osl/unx/profile.cxx
+++ b/sal/osl/unx/profile.cxx
@@ -1290,41 +1290,41 @@ static char* insertLine(osl_TProfileImpl* pProfile, const char* Line, sal_uInt32
 
 static void removeLine(osl_TProfileImpl* pProfile, sal_uInt32 LineNo)
 {
-    if (LineNo < pProfile->m_NoLines)
+    if (LineNo >= pProfile->m_NoLines)
+        return;
+
+    free(pProfile->m_Lines[LineNo]);
+    pProfile->m_Lines[LineNo]=nullptr;
+    if (pProfile->m_NoLines - LineNo > 1)
     {
-        free(pProfile->m_Lines[LineNo]);
-        pProfile->m_Lines[LineNo]=nullptr;
-        if (pProfile->m_NoLines - LineNo > 1)
-        {
-            sal_uInt32 i, n;
+        sal_uInt32 i, n;
 
-            memmove(&pProfile->m_Lines[LineNo], &pProfile->m_Lines[LineNo + 1],
-                    (pProfile->m_NoLines - LineNo - 1) * sizeof(char *));
+        memmove(&pProfile->m_Lines[LineNo], &pProfile->m_Lines[LineNo + 1],
+                (pProfile->m_NoLines - LineNo - 1) * sizeof(char *));
 
-            memset(&pProfile->m_Lines[pProfile->m_NoLines - 1],
-                0,
-                (pProfile->m_MaxLines - pProfile->m_NoLines) * sizeof(char*));
+        memset(&pProfile->m_Lines[pProfile->m_NoLines - 1],
+            0,
+            (pProfile->m_MaxLines - pProfile->m_NoLines) * sizeof(char*));
 
-            /* adjust line references */
-            for (i = 0; i < pProfile->m_NoSections; i++)
-            {
-                osl_TProfileSection* pSec = &pProfile->m_Sections[i];
+        /* adjust line references */
+        for (i = 0; i < pProfile->m_NoSections; i++)
+        {
+            osl_TProfileSection* pSec = &pProfile->m_Sections[i];
 
-                if (pSec->m_Line > LineNo)
-                    pSec->m_Line--;
+            if (pSec->m_Line > LineNo)
+                pSec->m_Line--;
 
-                for (n = 0; n < pSec->m_NoEntries; n++)
-                    if (pSec->m_Entries[n].m_Line > LineNo)
-                        pSec->m_Entries[n].m_Line--;
-            }
-        }
-        else
-        {
-            pProfile->m_Lines[LineNo] = nullptr;
+            for (n = 0; n < pSec->m_NoEntries; n++)
+                if (pSec->m_Entries[n].m_Line > LineNo)
+                    pSec->m_Entries[n].m_Line--;
         }
-
-        pProfile->m_NoLines--;
     }
+    else
+    {
+        pProfile->m_Lines[LineNo] = nullptr;
+    }
+
+    pProfile->m_NoLines--;
 }
 
 static void setEntry(osl_TProfileImpl* pProfile, osl_TProfileSection* pSection,
@@ -1381,21 +1381,21 @@ static bool addEntry(osl_TProfileImpl* pProfile,
 
 static void removeEntry(osl_TProfileSection *pSection, sal_uInt32 NoEntry)
 {
-    if (NoEntry < pSection->m_NoEntries)
-    {
-        if (pSection->m_NoEntries - NoEntry > 1)
-        {
-            memmove(&pSection->m_Entries[NoEntry],
-                    &pSection->m_Entries[NoEntry + 1],
-                    (pSection->m_NoEntries - NoEntry - 1) * sizeof(osl_TProfileEntry));
-            pSection->m_Entries[pSection->m_NoEntries - 1].m_Line=0;
-            pSection->m_Entries[pSection->m_NoEntries - 1].m_Offset=0;
-            pSection->m_Entries[pSection->m_NoEntries - 1].m_Len=0;
-        }
+    if (NoEntry >= pSection->m_NoEntries)
+        return;
 
-        pSection->m_NoEntries--;
+    if (pSection->m_NoEntries - NoEntry > 1)
+    {
+        memmove(&pSection->m_Entries[NoEntry],
+                &pSection->m_Entries[NoEntry + 1],
+                (pSection->m_NoEntries - NoEntry - 1) * sizeof(osl_TProfileEntry));
+        pSection->m_Entries[pSection->m_NoEntries - 1].m_Line=0;
+        pSection->m_Entries[pSection->m_NoEntries - 1].m_Offset=0;
+        pSection->m_Entries[pSection->m_NoEntries - 1].m_Len=0;
     }
 
+    pSection->m_NoEntries--;
+
 }
 
 static bool addSection(osl_TProfileImpl* pProfile, int Line, const char* Section, sal_uInt32 Len)
@@ -1450,27 +1450,27 @@ static void removeSection(osl_TProfileImpl* pProfile, osl_TProfileSection *pSect
 {
     sal_uInt32 Section;
 
-    if ((Section = pSection - pProfile->m_Sections) < pProfile->m_NoSections)
-    {
-        free (pSection->m_Entries);
-        pSection->m_Entries=nullptr;
-        if (pProfile->m_NoSections - Section > 1)
-        {
-            memmove(&pProfile->m_Sections[Section], &pProfile->m_Sections[Section + 1],
-                    (pProfile->m_NoSections - Section - 1) * sizeof(osl_TProfileSection));
+    if ((Section = pSection - pProfile->m_Sections) >= pProfile->m_NoSections)
+        return;
 
-            memset(&pProfile->m_Sections[pProfile->m_NoSections - 1],
-                   0,
-                   (pProfile->m_MaxSections - pProfile->m_NoSections) * sizeof(osl_TProfileSection));
-            pProfile->m_Sections[pProfile->m_NoSections - 1].m_Entries = nullptr;
-        }
-        else
-        {
-            pSection->m_Entries = nullptr;
-        }
+    free (pSection->m_Entries);
+    pSection->m_Entries=nullptr;
+    if (pProfile->m_NoSections - Section > 1)
+    {
+        memmove(&pProfile->m_Sections[Section], &pProfile->m_Sections[Section + 1],
+                (pProfile->m_NoSections - Section - 1) * sizeof(osl_TProfileSection));
 
-        pProfile->m_NoSections--;
+        memset(&pProfile->m_Sections[pProfile->m_NoSections - 1],
+               0,
+               (pProfile->m_MaxSections - pProfile->m_NoSections) * sizeof(osl_TProfileSection));
+        pProfile->m_Sections[pProfile->m_NoSections - 1].m_Entries = nullptr;
     }
+    else
+    {
+        pSection->m_Entries = nullptr;
+    }
+
+    pProfile->m_NoSections--;
 }
 
 static osl_TProfileSection* findEntry(osl_TProfileImpl* pProfile,
diff --git a/sal/osl/unx/signal.cxx b/sal/osl/unx/signal.cxx
index 00c3ca3f522e..79721def6c5e 100644
--- a/sal/osl/unx/signal.cxx
+++ b/sal/osl/unx/signal.cxx
@@ -334,43 +334,43 @@ void callSystemHandler(int signal, siginfo_t * info, void * context)
             break;
     }
 
-    if (i < NoSignals)
+    if (i >= NoSignals)
+        return;
+
+    if ((Signals[i].Handler == SIG_DFL) ||
+        (Signals[i].Handler == SIG_IGN) ||
+         (Signals[i].Handler == SIG_ERR))
     {
-        if ((Signals[i].Handler == SIG_DFL) ||
-            (Signals[i].Handler == SIG_IGN) ||
-             (Signals[i].Handler == SIG_ERR))
+        switch (Signals[i].Action)
         {
-            switch (Signals[i].Action)
-            {
-                case ACT_EXIT:      /* terminate */
-                    /* prevent dumping core on exit() */
-                    _exit(255);
-                    break;
-
-                case ACT_ABORT:     /* terminate with core dump */
-                    struct sigaction act;
-                    act.sa_handler = SIG_DFL;
-                    act.sa_flags   = 0;
-                    sigemptyset(&(act.sa_mask));
-                    sigaction(SIGABRT, &act, nullptr);
-                    printStack( signal );
-                    abort();
-                    break;
-
-                case ACT_IGNORE:    /* ignore */
-                    break;
-
-                default:            /* should never happen */
-                    OSL_ASSERT(false);
-            }
-        }
-        else if (Signals[i].siginfo) {
-            (*reinterpret_cast<Handler2>(Signals[i].Handler))(
-                signal, info, context);
-        } else {
-            (*Signals[i].Handler)(signal);
+            case ACT_EXIT:      /* terminate */
+                /* prevent dumping core on exit() */
+                _exit(255);
+                break;
+
+            case ACT_ABORT:     /* terminate with core dump */
+                struct sigaction act;
+                act.sa_handler = SIG_DFL;
+                act.sa_flags   = 0;
+                sigemptyset(&(act.sa_mask));
+                sigaction(SIGABRT, &act, nullptr);
+                printStack( signal );
+                abort();
+                break;
+
+            case ACT_IGNORE:    /* ignore */
+                break;
+
+            default:            /* should never happen */
+                OSL_ASSERT(false);
         }
     }
+    else if (Signals[i].siginfo) {
+        (*reinterpret_cast<Handler2>(Signals[i].Handler))(
+            signal, info, context);
+    } else {
+        (*Signals[i].Handler)(signal);
+    }
 }
 
 #if defined HAVE_VALGRIND_HEADERS
diff --git a/sal/rtl/bootstrap.cxx b/sal/rtl/bootstrap.cxx
index 97cbd1f79e0a..460786c77b1e 100644
--- a/sal/rtl/bootstrap.cxx
+++ b/sal/rtl/bootstrap.cxx
@@ -683,19 +683,19 @@ void SAL_CALL rtl_bootstrap_args_close(rtlBootstrapHandle handle) SAL_THROW_EXTE
     OSL_ASSERT(p_bootstrap_map->find(that->_iniName)->second == that);
     --that->_nRefCount;
 
-    if (that->_nRefCount == 0)
+    if (that->_nRefCount != 0)
+        return;
+
+    std::size_t const nLeaking = 8; // only hold up to 8 files statically
+    if (p_bootstrap_map->size() > nLeaking)
     {
-        std::size_t const nLeaking = 8; // only hold up to 8 files statically
-        if (p_bootstrap_map->size() > nLeaking)
-        {
-            ::std::size_t erased = p_bootstrap_map->erase( that->_iniName );
-            if (erased != 1) {
-                OSL_ASSERT( false );
-            }
-            delete that;
+        ::std::size_t erased = p_bootstrap_map->erase( that->_iniName );
+        if (erased != 1) {
+            OSL_ASSERT( false );
         }
-        bootstrap_map::release();
+        delete that;
     }
+    bootstrap_map::release();
 }
 
 sal_Bool SAL_CALL rtl_bootstrap_get_from_handle(
@@ -725,18 +725,18 @@ void SAL_CALL rtl_bootstrap_get_iniName_from_handle (
     rtl_uString     ** ppIniName
 )
 {
-    if(ppIniName)
+    if(!ppIniName)
+        return;
+
+    if(handle)
     {
-        if(handle)
-        {
-            Bootstrap_Impl * pImpl = static_cast<Bootstrap_Impl*>(handle);
-            rtl_uString_assign(ppIniName, pImpl->_iniName.pData);
-        }
-        else
-        {
-            const OUString & iniName = getIniFileName_Impl();
-            rtl_uString_assign(ppIniName, iniName.pData);
-        }
+        Bootstrap_Impl * pImpl = static_cast<Bootstrap_Impl*>(handle);
+        rtl_uString_assign(ppIniName, pImpl->_iniName.pData);
+    }
+    else
+    {
+        const OUString & iniName = getIniFileName_Impl();
+        rtl_uString_assign(ppIniName, iniName.pData);
     }
 }
 
diff --git a/sal/rtl/cipher.cxx b/sal/rtl/cipher.cxx
index be69d045a0ec..34428654975f 100644
--- a/sal/rtl/cipher.cxx
+++ b/sal/rtl/cipher.cxx
@@ -1139,20 +1139,20 @@ rtlCipherError SAL_CALL rtl_cipher_decodeBF(
 void SAL_CALL rtl_cipher_destroyBF(rtlCipher Cipher) SAL_THROW_EXTERN_C()
 {
     CipherBF_Impl *pImpl = static_cast<CipherBF_Impl*>(Cipher);
-    if (pImpl)
+    if (!pImpl)
+        return;
+
+    if (pImpl->m_cipher.m_algorithm == rtl_Cipher_AlgorithmBF)
     {
-        if (pImpl->m_cipher.m_algorithm == rtl_Cipher_AlgorithmBF)
-        {
 #if defined LIBO_CIPHER_OPENSSL_BACKEND
-            if (pImpl->m_context.m_context != nullptr) {
-                EVP_CIPHER_CTX_free(pImpl->m_context.m_context);
-            }
-#endif
-            rtl_freeZeroMemory(pImpl, sizeof(CipherBF_Impl));
+        if (pImpl->m_context.m_context != nullptr) {
+            EVP_CIPHER_CTX_free(pImpl->m_context.m_context);
         }
-        else
-            free(pImpl);
+#endif
+        rtl_freeZeroMemory(pImpl, sizeof(CipherBF_Impl));
     }
+    else
+        free(pImpl);
 }
 
 #if !defined LIBO_CIPHER_OPENSSL_BACKEND
@@ -1414,20 +1414,20 @@ rtlCipherError SAL_CALL rtl_cipher_decodeARCFOUR(
 void SAL_CALL rtl_cipher_destroyARCFOUR(rtlCipher Cipher) SAL_THROW_EXTERN_C()
 {
     CipherARCFOUR_Impl *pImpl = static_cast<CipherARCFOUR_Impl*>(Cipher);
-    if (pImpl)
+    if (!pImpl)
+        return;
+
+    if (pImpl->m_cipher.m_algorithm == rtl_Cipher_AlgorithmARCFOUR)
     {
-        if (pImpl->m_cipher.m_algorithm == rtl_Cipher_AlgorithmARCFOUR)
-        {
 #if defined LIBO_CIPHER_OPENSSL_BACKEND
-            if (pImpl->m_context.m_context != nullptr) {
-                EVP_CIPHER_CTX_free(pImpl->m_context.m_context);
-            }
-#endif
-            rtl_freeZeroMemory(pImpl, sizeof(CipherARCFOUR_Impl));
+        if (pImpl->m_context.m_context != nullptr) {
+            EVP_CIPHER_CTX_free(pImpl->m_context.m_context);
         }
-        else
-            free(pImpl);
+#endif
+        rtl_freeZeroMemory(pImpl, sizeof(CipherARCFOUR_Impl));
     }
+    else
+        free(pImpl);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/rtl/cmdargs.cxx b/sal/rtl/cmdargs.cxx
index 2d39aebd57c8..8eb328258dfe 100644
--- a/sal/rtl/cmdargs.cxx
+++ b/sal/rtl/cmdargs.cxx
@@ -48,31 +48,31 @@ ArgHolder argHolder;
 void init()
 {
     osl::MutexGuard guard( osl::Mutex::getGlobalMutex() );
-    if (!g_ppCommandArgs)
-    {
-        sal_Int32 i, n = osl_getCommandArgCount();
+    if (g_ppCommandArgs)
+        return;
+
+    sal_Int32 i, n = osl_getCommandArgCount();
 
-        g_ppCommandArgs =
-            static_cast<rtl_uString**>(rtl_allocateZeroMemory (n * sizeof(rtl_uString*)));
-        for (i = 0; i < n; i++)
+    g_ppCommandArgs =
+        static_cast<rtl_uString**>(rtl_allocateZeroMemory (n * sizeof(rtl_uString*)));
+    for (i = 0; i < n; i++)
+    {
+        rtl_uString * pArg = nullptr;
+        osl_getCommandArg (i, &pArg);
+        if ((pArg->buffer[0] == '-' || pArg->buffer[0] == '/') &&
+             pArg->buffer[1] == 'e' &&
+             pArg->buffer[2] == 'n' &&
+             pArg->buffer[3] == 'v' &&
+             pArg->buffer[4] == ':' &&
+            rtl_ustr_indexOfChar (&(pArg->buffer[5]), '=') >= 0 )
+        {
+            // ignore.
+            rtl_uString_release (pArg);
+        }
+        else
         {
-            rtl_uString * pArg = nullptr;
-            osl_getCommandArg (i, &pArg);
-            if ((pArg->buffer[0] == '-' || pArg->buffer[0] == '/') &&
-                 pArg->buffer[1] == 'e' &&
-                 pArg->buffer[2] == 'n' &&
-                 pArg->buffer[3] == 'v' &&
-                 pArg->buffer[4] == ':' &&
-                rtl_ustr_indexOfChar (&(pArg->buffer[5]), '=') >= 0 )
-            {
-                // ignore.
-                rtl_uString_release (pArg);
-            }
-            else
-            {
-                // assign.
-                g_ppCommandArgs[g_nCommandArgCount++] = pArg;
-            }
+            // assign.
+            g_ppCommandArgs[g_nCommandArgCount++] = pArg;
         }
     }
 }
diff --git a/sal/rtl/strbuf.cxx b/sal/rtl/strbuf.cxx
index da9ebaf689b0..b9f4cd688b05 100644
--- a/sal/rtl/strbuf.cxx
+++ b/sal/rtl/strbuf.cxx
@@ -79,25 +79,25 @@ void SAL_CALL rtl_stringbuffer_ensureCapacity
     assert(This);
 //    assert(capacity && *capacity >= 0);
 //    assert(minimumCapacity >= 0);
+    if (minimumCapacity <= *capacity)
+        return;
+
+    rtl_String * pTmp = *This;
+    rtl_String * pNew = nullptr;
+    auto nLength = (*This)->length;
+    *capacity = (nLength + 1) * 2;
     if (minimumCapacity > *capacity)
-    {
-        rtl_String * pTmp = *This;
-        rtl_String * pNew = nullptr;
-        auto nLength = (*This)->length;
-        *capacity = (nLength + 1) * 2;
-        if (minimumCapacity > *capacity)
-            /* still lower, set to the minimum capacity */
-            *capacity = minimumCapacity;
-
-        // use raw alloc to avoid overwriting the buffer twice
-        pNew = rtl_string_ImplAlloc( *capacity );
-        pNew->length = nLength;
-        *This = pNew;
-
-        memcpy( (*This)->buffer, pTmp->buffer, nLength );
-        memset( (*This)->buffer + nLength, 0, *capacity - nLength );
-        rtl_string_release( pTmp );
-    }
+        /* still lower, set to the minimum capacity */
+        *capacity = minimumCapacity;
+
+    // use raw alloc to avoid overwriting the buffer twice
+    pNew = rtl_string_ImplAlloc( *capacity );
+    pNew->length = nLength;
+    *This = pNew;
+
+    memcpy( (*This)->buffer, pTmp->buffer, nLength );
+    memset( (*This)->buffer + nLength, 0, *capacity - nLength );
+    rtl_string_release( pTmp );
 }
 
 /*************************************************************************
@@ -116,34 +116,34 @@ void SAL_CALL rtl_stringbuffer_insert( rtl_String ** This,
     sal_Int32 nOldLen;
     char * pBuf;
     sal_Int32 n;
-    if( len != 0 )
-    {
-        if (*capacity < (*This)->length + len)
-            rtl_stringbuffer_ensureCapacity( This, capacity, (*This)->length + len );
+    if( len == 0 )
+        return;
+
+    if (*capacity < (*This)->length + len)
+        rtl_stringbuffer_ensureCapacity( This, capacity, (*This)->length + len );
 
-        nOldLen = (*This)->length;
-        pBuf = (*This)->buffer;
+    nOldLen = (*This)->length;
+    pBuf = (*This)->buffer;
+
+    /* copy the tail */
+    n = (nOldLen - offset);
+    if( n == 1 )
+        /* optimized for 1 character */
+        pBuf[offset + len] = pBuf[offset];
+    else if( n > 1 )
+        memmove( pBuf + offset + len, pBuf + offset, n * sizeof(char) );
 
-        /* copy the tail */
-        n = (nOldLen - offset);
-        if( n == 1 )
+    /* insert the new characters */
+    if( str != nullptr )
+    {
+        if( len == 1 )
             /* optimized for 1 character */
-            pBuf[offset + len] = pBuf[offset];
-        else if( n > 1 )
-            memmove( pBuf + offset + len, pBuf + offset, n * sizeof(char) );
-
-        /* insert the new characters */
-        if( str != nullptr )
-        {
-            if( len == 1 )
-                            /* optimized for 1 character */
-                pBuf[offset] = *str;
-            else
-                memcpy( pBuf + offset, str, len * sizeof(char) );
-        }
-        (*This)->length = nOldLen + len;
-        pBuf[ nOldLen + len ] = 0;
+            pBuf[offset] = *str;
+        else
+            memcpy( pBuf + offset, str, len * sizeof(char) );
     }
+    (*This)->length = nOldLen + len;
+    pBuf[ nOldLen + len ] = 0;
 }
 
 /*************************************************************************
diff --git a/sal/rtl/ustrbuf.cxx b/sal/rtl/ustrbuf.cxx
index b6f66b9acd1e..53e178e5881a 100644
--- a/sal/rtl/ustrbuf.cxx
+++ b/sal/rtl/ustrbuf.cxx
@@ -103,27 +103,27 @@ void SAL_CALL rtl_uStringbuffer_ensureCapacity
     assert(This);
     assert(capacity && *capacity >= 0);
     assert(minimumCapacity >= 0);
+    if (minimumCapacity <= *capacity)
+        return;
+
+    rtl_uString * pTmp = *This;
+    rtl_uString * pNew = nullptr;
+    auto nLength = (*This)->length;
+    *capacity = (nLength + 1) * 2;
     if (minimumCapacity > *capacity)
-    {
-        rtl_uString * pTmp = *This;
-        rtl_uString * pNew = nullptr;
-        auto nLength = (*This)->length;
-        *capacity = (nLength + 1) * 2;
-        if (minimumCapacity > *capacity)
-            /* still lower, set to the minimum capacity */
-            *capacity = minimumCapacity;
-
-        // use raw alloc to avoid overwriting the buffer twice
-        pNew = rtl_uString_ImplAlloc( *capacity );
-        pNew->length = nLength;
-        *This = pNew;
-
-        memcpy( (*This)->buffer, pTmp->buffer, nLength * sizeof(sal_Unicode) );
-        memset( (*This)->buffer + nLength, 0, (*capacity - nLength) * sizeof(sal_Unicode) );
-
-        RTL_LOG_STRING_NEW( pTmp ); // with accurate contents
-        rtl_uString_release( pTmp );
-    }
+        /* still lower, set to the minimum capacity */
+        *capacity = minimumCapacity;
+
+    // use raw alloc to avoid overwriting the buffer twice
+    pNew = rtl_uString_ImplAlloc( *capacity );
+    pNew->length = nLength;
+    *This = pNew;
+
+    memcpy( (*This)->buffer, pTmp->buffer, nLength * sizeof(sal_Unicode) );
+    memset( (*This)->buffer + nLength, 0, (*capacity - nLength) * sizeof(sal_Unicode) );
+
+    RTL_LOG_STRING_NEW( pTmp ); // with accurate contents
+    rtl_uString_release( pTmp );
 }
 
 void SAL_CALL rtl_uStringbuffer_insert( rtl_uString ** This,
@@ -139,34 +139,34 @@ void SAL_CALL rtl_uStringbuffer_insert( rtl_uString ** This,
     sal_Int32 nOldLen;
     sal_Unicode * pBuf;
     sal_Int32 n;
-    if( len != 0 )
+    if( len == 0 )
+        return;
+
+    if (*capacity < (*This)->length + len)
+        rtl_uStringbuffer_ensureCapacity( This, capacity, (*This)->length + len );
+
+    nOldLen = (*This)->length;
+    pBuf = (*This)->buffer;
+
+    /* copy the tail */
+    n = (nOldLen - offset);
+    if( n == 1 )
+        /* optimized for 1 character */
+        pBuf[offset + len] = pBuf[offset];
+    else if( n > 1 )
+        memmove( pBuf + offset + len, pBuf + offset, n * sizeof(sal_Unicode) );
+
+    /* insert the new characters */
+    if( str != nullptr )
     {
-        if (*capacity < (*This)->length + len)
-            rtl_uStringbuffer_ensureCapacity( This, capacity, (*This)->length + len );
-
-        nOldLen = (*This)->length;
-        pBuf = (*This)->buffer;
-
-        /* copy the tail */
-        n = (nOldLen - offset);
-        if( n == 1 )
-                            /* optimized for 1 character */
-            pBuf[offset + len] = pBuf[offset];
-        else if( n > 1 )
-            memmove( pBuf + offset + len, pBuf + offset, n * sizeof(sal_Unicode) );
-
-        /* insert the new characters */
-        if( str != nullptr )
-        {
-            if( len == 1 )
-                /* optimized for 1 character */
-                pBuf[offset] = *str;
-            else
-                memcpy( pBuf + offset, str, len * sizeof(sal_Unicode) );
-        }
-        (*This)->length = nOldLen + len;
-        pBuf[ nOldLen + len ] = 0;
+        if( len == 1 )
+            /* optimized for 1 character */
+            pBuf[offset] = *str;
+        else
+            memcpy( pBuf + offset, str, len * sizeof(sal_Unicode) );
     }
+    (*This)->length = nOldLen + len;
+    pBuf[ nOldLen + len ] = 0;
 }
 
 void rtl_uStringbuffer_insertUtf32(
@@ -202,34 +202,34 @@ void SAL_CALL rtl_uStringbuffer_insert_ascii(   /*inout*/rtl_uString ** This,
     sal_Int32 nOldLen;
     sal_Unicode * pBuf;
     sal_Int32 n;
-    if( len != 0 )
-    {
-        if (*capacity < (*This)->length + len)
-            rtl_uStringbuffer_ensureCapacity( This, capacity, (*This)->length + len );
+    if( len == 0 )
+        return;
 
-        nOldLen = (*This)->length;
-        pBuf = (*This)->buffer;
+    if (*capacity < (*This)->length + len)
+        rtl_uStringbuffer_ensureCapacity( This, capacity, (*This)->length + len );
 
-        /* copy the tail */
-        n = (nOldLen - offset);
-        if( n == 1 )
-            /* optimized for 1 character */
-            pBuf[offset + len] = pBuf[offset];
-        else if( n > 1 )
-            memmove( pBuf + offset + len, pBuf + offset, n * sizeof(sal_Unicode) );
+    nOldLen = (*This)->length;
+    pBuf = (*This)->buffer;
 
-        /* insert the new characters */
-        for( n = 0; n < len; n++ )
-        {
-            /* Check ASCII range */
-            OSL_ENSURE( (*str & 0x80) == 0, "Found ASCII char > 127");
+    /* copy the tail */
+    n = (nOldLen - offset);
+    if( n == 1 )
+        /* optimized for 1 character */
+        pBuf[offset + len] = pBuf[offset];
+    else if( n > 1 )
+        memmove( pBuf + offset + len, pBuf + offset, n * sizeof(sal_Unicode) );
 
-            pBuf[offset + n] = static_cast<sal_Unicode>(*(str++));
-        }
+    /* insert the new characters */
+    for( n = 0; n < len; n++ )
+    {
+        /* Check ASCII range */
+        OSL_ENSURE( (*str & 0x80) == 0, "Found ASCII char > 127");
 
-        (*This)->length = nOldLen + len;
-        pBuf[ nOldLen + len ] = 0;
+        pBuf[offset + n] = static_cast<sal_Unicode>(*(str++));
     }
+
+    (*This)->length = nOldLen + len;
+    pBuf[ nOldLen + len ] = 0;
 }
 
 /*************************************************************************


More information about the Libreoffice-commits mailing list