mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-25 22:06:15 +00:00
Fix crashes reported by Bennet Helm and Kornel Benko
* src/support/unicode.[Ch] (IconvProcessor): Rework the implementation to fix two bugs: - iconv_close was called even if the conversion descriptor was invalid - The compiler generated copy constructor did simply copy the pimpl_ pointer. Therefore pimpl_ was deleted twice for all IconvProcessor instances created by eightbit_to_ucs4() and ucs4_to_eightbit(). This is solved by using a scoped_ptr for pimpl_. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15937 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
51a3125356
commit
2981181ec3
@ -39,6 +39,15 @@ static const iconv_t invalid_cd = (iconv_t)(-1);
|
||||
|
||||
struct IconvProcessor::Private {
|
||||
Private(): cd(invalid_cd) {}
|
||||
~Private()
|
||||
{
|
||||
if (cd != invalid_cd) {
|
||||
if (iconv_close(cd) == -1) {
|
||||
lyxerr << "Error returned from iconv_close("
|
||||
<< errno << ")" << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
iconv_t cd;
|
||||
};
|
||||
|
||||
@ -50,16 +59,27 @@ IconvProcessor::IconvProcessor(char const * tocode,
|
||||
}
|
||||
|
||||
|
||||
IconvProcessor::~IconvProcessor()
|
||||
IconvProcessor::IconvProcessor(IconvProcessor const & other)
|
||||
: tocode_(other.tocode_), fromcode_(other.fromcode_),
|
||||
pimpl_(new IconvProcessor::Private)
|
||||
{
|
||||
if (iconv_close(pimpl_->cd) == -1) {
|
||||
lyxerr << "Error returned from iconv_close("
|
||||
<< errno << ")" << endl;
|
||||
}
|
||||
delete pimpl_;
|
||||
}
|
||||
|
||||
|
||||
IconvProcessor & IconvProcessor::operator=(IconvProcessor const & other)
|
||||
{
|
||||
if (&other == this)
|
||||
return *this;
|
||||
tocode_ = other.tocode_;
|
||||
fromcode_ = other.fromcode_;
|
||||
pimpl_.reset(new Private);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
IconvProcessor::~IconvProcessor() {}
|
||||
|
||||
|
||||
bool IconvProcessor::init()
|
||||
{
|
||||
if (pimpl_->cd != invalid_cd)
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
#include "support/types.h"
|
||||
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -27,6 +29,12 @@ public:
|
||||
IconvProcessor(
|
||||
char const * tocode = "",
|
||||
char const * fromcode = "");
|
||||
/// copy constructor needed because of pimpl_
|
||||
IconvProcessor(IconvProcessor const &);
|
||||
/// assignment operator needed because of pimpl_
|
||||
IconvProcessor & operator=(IconvProcessor const &);
|
||||
/// destructor (needs to be implemented in the .C file because the
|
||||
/// boost::scoped_ptr destructor needs a fully defined type
|
||||
~IconvProcessor();
|
||||
|
||||
/// convert any data from \c fromcode to \c tocode unicode format.
|
||||
@ -45,7 +53,7 @@ private:
|
||||
std::string fromcode_;
|
||||
|
||||
struct Private;
|
||||
Private * pimpl_;
|
||||
boost::scoped_ptr<Private> pimpl_;
|
||||
};
|
||||
|
||||
// utf8_to_ucs4
|
||||
|
Loading…
Reference in New Issue
Block a user