Re: ib - r30529 - abiword/trunk/plugins/mswrite/xp

From: Hub Figuière <hfiguiere_at_teaser.fr>
Date: Sat Dec 24 2011 - 21:00:52 CET

On 24/12/11 02:32 AM, cvs@abisource.com wrote:
>
> Author: ib
> Date: 2011-12-24 11:32:44 +0100 (Sat, 24 Dec 2011)
> New Revision: 30529
>
> Modified:
> abiword/trunk/plugins/mswrite/xp/ie_imp_MSWrite.cpp
> Log:
> Revert r30527.
>
> There is no error.
>
> The property exists as long as the importer class exists.

> @@ -296,10 +294,7 @@
> setProps(AP_Args::m_impProps);
> const std::string propCP = getProperty("mswrite-codepage");
>
> - if (!propCP.empty()) {
> - strncpy(s_cpbuffer,propCP.c_str(),30);
> - default_codepage = s_cpbuffer;
> - }
> + if (!propCP.empty()) default_codepage = propCP.c_str();

There is a bug. But the way it was addressed by Urmarstl was not good.

when propCP goes out of scope (ie when the constructor ends), the string
that c_str() returns becomes invalid making "default_codepage" invalid.

Using a global static string buffer is bad too.

The best fix at that point is to make "default_codepage" a std::string.
And while we are at it, rename it "m_default_codepage", because it is a
member variable.
And the statement after the if() goes on the next line, possibly with
curly braces.

Cheers,

Hub
Received on Sat Dec 24 21:01:07 2011

This archive was generated by hypermail 2.1.8 : Sat Dec 24 2011 - 21:01:07 CET