Re: urmaslt - r29621 - abiword/trunk/plugins/mswrite/xp

From: Jean Brefort <jean.brefort_at_normalesup.org>
Date: Thu Mar 03 2011 - 16:48:42 CET

Still two issues:

line 278:
                                wri_fonts[i].codepage="CP1252";

assigning a const char* to a char* that might/will be freed.

same thing at line 295:
static struct cst_data {
        char *suffix;
        char *cpid;
} cp_suf_tbl[]={
        {"\x04 cyr","CP1251"},
        {"\x03 ce","CP1250"},
        {NULL,NULL}
};

In that case const char* is probably better. I'm not sure that these
will be freed at any time, but this would make gcc happy.

Jean

Le jeudi 03 mars 2011 à 09:59 +0100, cvs@abisource.com a écrit :
> Author: urmaslt
> Date: 2011-03-03 09:59:44 +0100 (Thu, 03 Mar 2011)
> New Revision: 29621
>
> Modified:
> abiword/trunk/plugins/mswrite/xp/ie_imp_MSWrite.cpp
> abiword/trunk/plugins/mswrite/xp/ie_imp_MSWrite.h
> Log:
> Some cleanup.
>
> Modified: abiword/trunk/plugins/mswrite/xp/ie_imp_MSWrite.cpp
> ===================================================================
> --- abiword/trunk/plugins/mswrite/xp/ie_imp_MSWrite.cpp 2011-03-03 06:30:19 UTC (rev 29620)
> +++ abiword/trunk/plugins/mswrite/xp/ie_imp_MSWrite.cpp 2011-03-03 08:59:44 UTC (rev 29621)
> @@ -31,7 +31,7 @@
> */
>
> #include <stdio.h>
> -#include <stdlib.h>
> +//#include <stdlib.h>
> #include <string.h>
> #include <set>
> #include "ut_locale.h"
> @@ -296,31 +296,31 @@
>
> void IE_Imp_MSWrite::translate_char (char ch, UT_UCS4String &buf)
> {
> - UT_UCS4Char uch=ch;
> + UT_UCS4Char uch=ch;
>
> - lf = false;
> + lf = false;
>
> - switch (ch)
> - {
> - case 9:
> - buf += UCS_TAB;
> - break;
> + switch (ch)
> + {
> + case 9:
> + buf += UCS_TAB;
> + break;
>
> - case 12:
> - buf += UCS_FF;
> - break;
> + case 12:
> + buf += UCS_FF;
> + break;
>
> - case 10: /* line feed */
> - lf = true;
> - case 13: /* carriage return */
> - case 31: /* soft hyphen */
> - break;
> - default:
> + case 10: /* line feed */
> + lf = true;
> + case 13: /* carriage return */
> + case 31: /* soft hyphen */
> + break;
> + default:
> if (ch & 0x80) {
> charconv.mbtowc(uch, ch);
> - }
> + }
> buf += uch;
> - }
> + }
> }
>
> char *IE_Imp_MSWrite::get_codepage(char *facename, char **newname)
> @@ -565,6 +565,8 @@
> UT_String propBuffer;
> UT_String tempBuffer;
>
> + const char *oldcp = "";
> +
> fcMac = wri_struct_value (write_file_header, "fcMac");
> page = (fcMac + 127) / 128;
> fcFirst = 0x80;
> @@ -618,7 +620,7 @@
> if (hps != 24) {
> UT_String_sprintf(tempBuffer, "; font-size:%dpt", hps / 2);
> propBuffer += tempBuffer;
> - }
> + }
> if (italic) {
> propBuffer += "; font-style:italic";
> }
> @@ -634,7 +636,12 @@
> UT_String_sprintf (tempBuffer, "; font-family:%s", wri_fonts[ftc].name);
> propBuffer += tempBuffer;
> }
> - set_codepage(wri_fonts[ftc].codepage);
> + const char *needcp = wri_fonts[ftc].codepage ?
> + wri_fonts[ftc].codepage : default_cp.c_str();
> + if (needcp != oldcp /*sic!*/) {
> + set_codepage((char*)needcp);
> + oldcp = needcp;
> + }
> while (fcFirst2 >= fcFirst) {
> if ((fcFirst2 >= fcLim) || (fcFirst2 > fcLim2) ||
> (fcFirst2 - 0x80 >= static_cast<UT_sint32>(mTextBuf.getLength()))) {
> @@ -645,13 +652,12 @@
> }
>
> const gchar* propsArray[3];
> - propsArray[0] = PT_PROPS_ATTRIBUTE_NAME;
> - propsArray[1] = propBuffer.c_str();
> - propsArray[2] = NULL;
> -
> if (mCharBuf.size() > 0) {
> + propsArray[0] = PT_PROPS_ATTRIBUTE_NAME;
> + propsArray[1] = propBuffer.c_str();
> + propsArray[2] = NULL;
> +
> appendFmt (propsArray);
> - UT_DEBUGMSG (("Hub: About to append %zd chars of text\n", mCharBuf.size()));
> appendSpan (reinterpret_cast<const UT_UCSChar *>(mCharBuf.ucs4_str()), mCharBuf.size());
> }
> else {
> @@ -807,10 +813,10 @@
>
> IE_Imp_MSWrite::IE_Imp_MSWrite(PD_Document * pDocument)
> : IE_Imp(pDocument), mFile(0), wri_fonts_count(0),
> - wri_fonts(0), pic_nr(0),
> + wri_fonts(0), pic_nr(0), default_cp("CP1252"),
> lf(false)
> {
> - charconv.setInCharset("CP1252");
> + set_codepage((char*)default_cp.c_str());
>
> write_file_header = static_cast<struct wri_struct*>(malloc (sizeof (WRITE_FILE_HEADER)));
> memcpy (write_file_header, WRITE_FILE_HEADER, sizeof (WRITE_FILE_HEADER));
>
> Modified: abiword/trunk/plugins/mswrite/xp/ie_imp_MSWrite.h
> ===================================================================
> --- abiword/trunk/plugins/mswrite/xp/ie_imp_MSWrite.h 2011-03-03 06:30:19 UTC (rev 29620)
> +++ abiword/trunk/plugins/mswrite/xp/ie_imp_MSWrite.h 2011-03-03 08:59:44 UTC (rev 29621)
> @@ -95,6 +95,7 @@
> struct wri_struct *write_picture;
> struct wri_struct *write_ole_picture;
>
> + std::string default_cp;
> UT_UCS4Char *transtbl; // table for decoding codepage-specific symbols
> char *get_codepage(char *facename, char **newname=NULL); // gets cp id by font name;
> void set_codepage(char *cp); // sets the translation table to corresponding codeset
>
> -----------------------------------------------
> To unsubscribe from this list, send a message to
> abisource-cvs-commit-request@abisource.com with the word
> unsubscribe in the message body.
Received on Thu Mar 3 16:48:29 2011

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2011 - 16:48:29 CET