summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJochen Nitschke <j.nitschke+logerrit@ok.de>2016-11-23 19:49:21 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2016-11-24 05:09:05 +0000
commitb367c81d06f64e500063ebb814eda5e8d55309ca (patch)
treebefb401f63253018cd8accb5902d314101c4db78 /tools
parent50106435e9a5bbc067e9beeabc5147ed9f305286 (diff)
replace custom list with std::forward_list
cppcheck warns with publicAllocationError in INetMIMECharsetList_Impl::prepend(...) > { m_pFirst = new Node(rCharset, m_pFirst); }<--- Possible leak > in public function. The pointer 'm_pFirst' is not deallocated before > it is allocated. We got a single linked list here which is correctly deallocated in dtor. But with C++11 std::forward_list there is no reason to implement or own list. Change-Id: Ia6582061c1e5f1284bd81fafef88ce475ee891aa Reviewed-on: https://gerrit.libreoffice.org/31132 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'tools')
-rw-r--r--tools/source/inet/inetmime.cxx49
1 files changed, 16 insertions, 33 deletions
diff --git a/tools/source/inet/inetmime.cxx b/tools/source/inet/inetmime.cxx
index 34fb6aa5df46..05ae7cb91c15 100644
--- a/tools/source/inet/inetmime.cxx
+++ b/tools/source/inet/inetmime.cxx
@@ -18,6 +18,7 @@
*/
#include <cstddef>
+#include <forward_list>
#include <limits>
#include <memory>
@@ -429,20 +430,19 @@ class INetMIMECharsetList_Impl
{
Charset m_aCharset;
bool m_bDisabled;
- Node * m_pNext;
- inline Node(const Charset & rTheCharset, Node * pTheNext);
+ explicit Node(const Charset & rCharset)
+ :m_aCharset(rCharset), m_bDisabled(false)
+ {}
};
- Node * m_pFirst;
+ std::forward_list<Node> m_aList;
public:
- INetMIMECharsetList_Impl(): m_pFirst(nullptr) {}
-
- ~INetMIMECharsetList_Impl();
-
void prepend(const Charset & rCharset)
- { m_pFirst = new Node(rCharset, m_pFirst); }
+ {
+ m_aList.emplace_front(rCharset);
+ }
void includes(sal_uInt32 nChar);
@@ -452,13 +452,6 @@ public:
void reset();
};
-inline INetMIMECharsetList_Impl::Node::Node(const Charset & rTheCharset,
- Node * pTheNext):
- m_aCharset(rTheCharset),
- m_bDisabled(false),
- m_pNext(pTheNext)
-{}
-
struct Parameter
{
Parameter * m_pNext;
@@ -539,36 +532,26 @@ void appendISO88591(OUString & rText, sal_Char const * pBegin,
// INetMIMECharsetList_Impl
-INetMIMECharsetList_Impl::~INetMIMECharsetList_Impl()
-{
- while (m_pFirst)
- {
- Node * pRemove = m_pFirst;
- m_pFirst = m_pFirst->m_pNext;
- delete pRemove;
- }
-}
-
void INetMIMECharsetList_Impl::includes(sal_uInt32 nChar)
{
- for (Node * p = m_pFirst; p; p = p->m_pNext)
- if (!(p->m_bDisabled || p->m_aCharset.contains(nChar)))
- p->m_bDisabled = true;
+ for (Node& rNode : m_aList)
+ if (!(rNode.m_bDisabled || rNode.m_aCharset.contains(nChar)))
+ rNode.m_bDisabled = true;
}
rtl_TextEncoding INetMIMECharsetList_Impl::getPreferredEncoding(rtl_TextEncoding eDefault)
const
{
- for (Node * p = m_pFirst; p; p = p->m_pNext)
- if (!p->m_bDisabled)
- return p->m_aCharset.getEncoding();
+ for (const Node& rNode : m_aList)
+ if (!rNode.m_bDisabled)
+ return rNode.m_aCharset.getEncoding();
return eDefault;
}
void INetMIMECharsetList_Impl::reset()
{
- for (Node * p = m_pFirst; p; p = p->m_pNext)
- p->m_bDisabled = false;
+ for (Node& rNode : m_aList)
+ rNode.m_bDisabled = false;
}
// ParameterList