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:
parent
3d27b1148b
commit
9780be6c05
@ -30,9 +30,7 @@ enum
|
|||||||
MAXSTYLENAME = 20
|
MAXSTYLENAME = 20
|
||||||
};
|
};
|
||||||
|
|
||||||
#define DATA static_cast<StyleData*>(style)
|
namespace hwpfilter
|
||||||
|
|
||||||
namespace
|
|
||||||
{
|
{
|
||||||
struct StyleData
|
struct StyleData
|
||||||
{
|
{
|
||||||
@ -52,7 +50,7 @@ HWPStyle::HWPStyle()
|
|||||||
|
|
||||||
HWPStyle::~HWPStyle()
|
HWPStyle::~HWPStyle()
|
||||||
{
|
{
|
||||||
delete[] DATA;
|
delete[] style;
|
||||||
nstyles = 0;
|
nstyles = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,7 +58,7 @@ char* HWPStyle::GetName(int n) const
|
|||||||
{
|
{
|
||||||
if (n < 0 || n >= nstyles)
|
if (n < 0 || n >= nstyles)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return DATA[n].name;
|
return style[n].name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HWPStyle::SetName(int n, char const* 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 push
|
||||||
#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
#pragma GCC diagnostic ignored "-Wstringop-truncation"
|
||||||
#endif
|
#endif
|
||||||
auto const p = DATA[n].name;
|
auto const p = style[n].name;
|
||||||
strncpy(p, name, MAXSTYLENAME);
|
strncpy(p, name, MAXSTYLENAME);
|
||||||
p[MAXSTYLENAME] = '\0'; // just in case, even though the array is zero-initialized
|
p[MAXSTYLENAME] = '\0'; // just in case, even though the array is zero-initialized
|
||||||
#if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 11) && !defined __clang__
|
#if defined __GNUC__ && (__GNUC__ >= 8 && __GNUC__ <= 11) && !defined __clang__
|
||||||
@ -82,14 +80,14 @@ void HWPStyle::SetName(int n, char const* name)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
DATA[n].name[0] = 0;
|
style[n].name[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CharShape* HWPStyle::GetCharShape(int n) const
|
CharShape* HWPStyle::GetCharShape(int n) const
|
||||||
{
|
{
|
||||||
if (n < 0 || n >= nstyles)
|
if (n < 0 || n >= nstyles)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return &DATA[n].cshape;
|
return &style[n].cshape;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HWPStyle::SetCharShape(int n, CharShape const* cshapep)
|
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 (n >= 0 && n < nstyles)
|
||||||
{
|
{
|
||||||
if (cshapep)
|
if (cshapep)
|
||||||
DATA[n].cshape = *cshapep;
|
style[n].cshape = *cshapep;
|
||||||
else
|
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)
|
if (n < 0 || n >= nstyles)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return &DATA[n].pshape;
|
return &style[n].pshape;
|
||||||
}
|
}
|
||||||
|
|
||||||
void HWPStyle::SetParaShape(int n, ParaShape const* pshapep)
|
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 (n >= 0 && n < nstyles)
|
||||||
{
|
{
|
||||||
if (pshapep)
|
if (pshapep)
|
||||||
DATA[n].pshape = *pshapep;
|
style[n].pshape = *pshapep;
|
||||||
else
|
else
|
||||||
DATA[n].pshape = ParaShape();
|
style[n].pshape = ParaShape();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +125,7 @@ void HWPStyle::Read(HWPFile& hwpf)
|
|||||||
ParaShape pshape;
|
ParaShape pshape;
|
||||||
|
|
||||||
hwpf.Read2b(&nstyles, 1);
|
hwpf.Read2b(&nstyles, 1);
|
||||||
style = ::comphelper::newArray_null<StyleData>(nstyles);
|
style = ::comphelper::newArray_null<hwpfilter::StyleData>(nstyles);
|
||||||
if (!style)
|
if (!style)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -25,13 +25,16 @@
|
|||||||
|
|
||||||
#include "hwplib.h"
|
#include "hwplib.h"
|
||||||
#include "hinfo.h"
|
#include "hinfo.h"
|
||||||
|
|
||||||
|
namespace hwpfilter { struct StyleData; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @short Using for global style object like "Standard"
|
* @short Using for global style object like "Standard"
|
||||||
*/
|
*/
|
||||||
class DLLEXPORT HWPStyle
|
class DLLEXPORT HWPStyle
|
||||||
{
|
{
|
||||||
short nstyles;
|
short nstyles;
|
||||||
void *style;
|
hwpfilter::StyleData *style;
|
||||||
public:
|
public:
|
||||||
HWPStyle( void );
|
HWPStyle( void );
|
||||||
~HWPStyle( void );
|
~HWPStyle( void );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user