From 3a518c0536e5986b740c583e4b71152a414ac90b Mon Sep 17 00:00:00 2001 From: wang-bin Date: Wed, 4 Nov 2015 18:16:24 +0800 Subject: [PATCH] do not use std::string which breaks c++ abi Some stl types can break abi. If the program is built with g++ 5, and libstdc++ on the target platform is g++ 4.x, then it can not run --- src/uchardet.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/uchardet.cpp b/src/uchardet.cpp index 74ab63c..7815e46 100644 --- a/src/uchardet.cpp +++ b/src/uchardet.cpp @@ -35,41 +35,47 @@ * * ***** END LICENSE BLOCK ***** */ #include "uchardet.h" +#include +#include #include "nscore.h" #include "nsUniversalDetector.h" -#include - -using std::string; class HandleUniversalDetector : public nsUniversalDetector { protected: - string m_charset; + char *m_charset; public: HandleUniversalDetector() : nsUniversalDetector(NS_FILTER_ALL) + , m_charset(0) { - m_charset = ""; } virtual ~HandleUniversalDetector() - {} + { + if (m_charset) + free(m_charset); + } virtual void Report(const char* charset) { - m_charset = charset; + if (m_charset) + free(m_charset); + m_charset = strdup(charset); } virtual void Reset() { nsUniversalDetector::Reset(); - m_charset = ""; + if (m_charset) + free(m_charset); + m_charset = strdup(""); } const char* GetCharset() const { - return m_charset.c_str(); + return m_charset; } };