Make HWPStyle::style type-safe

Change-Id: I3a8dcf497a236d12eedff9e7b5943e14747cb9bb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128374
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann 2022-01-13 12:11:43 +01:00
parent 3d27b1148b
commit 9780be6c05
2 changed files with 16 additions and 15 deletions

View file

@ -30,9 +30,7 @@ enum
MAXSTYLENAME = 20
};
#define DATA static_cast<StyleData*>(style)
namespace
namespace hwpfilter
{
struct StyleData
{
@ -52,7 +50,7 @@ HWPStyle::HWPStyle()
HWPStyle::~HWPStyle()
{
delete[] DATA;
delete[] style;
nstyles = 0;
}
@ -60,7 +58,7 @@ char* HWPStyle::GetName(int n) const
{
if (n < 0 || n >= nstyles)
return nullptr;
return DATA[n].name;
return style[n].name;
}
void HWPStyle::SetName(int n, char const* name)
@ -74,7 +72,7 @@ void HWPStyle::SetName(int n, char const* name)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
#endif
auto const p = DATA[n].name;
auto const p = style[n].name;
strncpy(p, name, MAXSTYLENAME);
p[MAXSTYLENAME] = '\0'; // just in case, even though the array is zero-initialized
#if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 11) && !defined __clang__
@ -82,14 +80,14 @@ void HWPStyle::SetName(int n, char const* name)
#endif
}
else
DATA[n].name[0] = 0;
style[n].name[0] = 0;
}
CharShape* HWPStyle::GetCharShape(int n) const
{
if (n < 0 || n >= nstyles)
return nullptr;
return &DATA[n].cshape;
return &style[n].cshape;
}
void HWPStyle::SetCharShape(int n, CharShape const* cshapep)
@ -97,9 +95,9 @@ void HWPStyle::SetCharShape(int n, CharShape const* cshapep)
if (n >= 0 && n < nstyles)
{
if (cshapep)
DATA[n].cshape = *cshapep;
style[n].cshape = *cshapep;
else
memset(&DATA[n].cshape, 0, sizeof(CharShape));
memset(&style[n].cshape, 0, sizeof(CharShape));
}
}
@ -107,7 +105,7 @@ ParaShape* HWPStyle::GetParaShape(int n) const
{
if (n < 0 || n >= nstyles)
return nullptr;
return &DATA[n].pshape;
return &style[n].pshape;
}
void HWPStyle::SetParaShape(int n, ParaShape const* pshapep)
@ -115,9 +113,9 @@ void HWPStyle::SetParaShape(int n, ParaShape const* pshapep)
if (n >= 0 && n < nstyles)
{
if (pshapep)
DATA[n].pshape = *pshapep;
style[n].pshape = *pshapep;
else
DATA[n].pshape = ParaShape();
style[n].pshape = ParaShape();
}
}
@ -127,7 +125,7 @@ void HWPStyle::Read(HWPFile& hwpf)
ParaShape pshape;
hwpf.Read2b(&nstyles, 1);
style = ::comphelper::newArray_null<StyleData>(nstyles);
style = ::comphelper::newArray_null<hwpfilter::StyleData>(nstyles);
if (!style)
return;

View file

@ -25,13 +25,16 @@
#include "hwplib.h"
#include "hinfo.h"
namespace hwpfilter { struct StyleData; }
/**
* @short Using for global style object like "Standard"
*/
class DLLEXPORT HWPStyle
{
short nstyles;
void *style;
hwpfilter::StyleData *style;
public:
HWPStyle( void );
~HWPStyle( void );