diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-02 10:58:02 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-02 20:06:15 +0200 |
commit | 4acb0e7f05fa7fe05f990786e0483e20962af1d9 (patch) | |
tree | 03ca9e43ae3118c3cf97efecda3b21649ae9ed69 /sal/rtl | |
parent | d8af42ec5004c8cdb57b6aa60a0f811cf61ad355 (diff) |
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@collabora.co.uk>
Diffstat (limited to 'sal/rtl')
-rw-r--r-- | sal/rtl/bootstrap.cxx | 42 | ||||
-rw-r--r-- | sal/rtl/cipher.cxx | 40 | ||||
-rw-r--r-- | sal/rtl/cmdargs.cxx | 46 | ||||
-rw-r--r-- | sal/rtl/strbuf.cxx | 84 | ||||
-rw-r--r-- | sal/rtl/ustrbuf.cxx | 136 |
5 files changed, 174 insertions, 174 deletions
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; } /************************************************************************* |