hwpfilter/source/hstyle.cxx | 26 ++++++++++++-------------- hwpfilter/source/hstyle.h | 5 ++++- 2 files changed, 16 insertions(+), 15 deletions(-)
New commits: commit 9780be6c05ece20d292035f6aba50dab34a8b024 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Thu Jan 13 12:11:43 2022 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Thu Jan 13 14:29:12 2022 +0100 Make HWPStyle::style type-safe Change-Id: I3a8dcf497a236d12eedff9e7b5943e14747cb9bb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128374 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/hwpfilter/source/hstyle.cxx b/hwpfilter/source/hstyle.cxx index fbbe30025d0a..23ae86c68538 100644 --- a/hwpfilter/source/hstyle.cxx +++ b/hwpfilter/source/hstyle.cxx @@ -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; diff --git a/hwpfilter/source/hstyle.h b/hwpfilter/source/hstyle.h index 66fa09634afb..851bd8d4d164 100644 --- a/hwpfilter/source/hstyle.h +++ b/hwpfilter/source/hstyle.h @@ -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 );