summaryrefslogtreecommitdiff
path: root/hwpfilter/source
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2019-01-18 16:11:27 +0100
committerStephan Bergmann <sbergman@redhat.com>2019-01-21 09:38:13 +0100
commit26688cf08988ad80f7412d00dba749faa06832ad (patch)
treef74ce2122703202444f2d18e62dcef794faa9d57 /hwpfilter/source
parent3a001a588c43cf8c2c3f6cb6a6796cc1bf8e2683 (diff)
Avoid -Werror=stringop-truncation
...as emitted by at least GCC 8.2 with --enable-optimized. These are not actually problems, as in both cases strncpy(p,...,N-1) is used to copy a string into an area p of length N that has initially been zero-initialized, so p[N-1] will already contain NUL. But add the (redundant) p[N-1]=NUL just in case, and to silence GCC (where the documentation explicitly recommends this additional write as a way to silence the warning). Unfortunately, in hstyle.cxx at least GCC 8.2 with --enable-optimized would still emit the warning, even though it uses the recommended way of handling it, so needs to be silenced with a #pragma. Change-Id: Ie41f420c732c2bfb699903ebd21ce1a89dd2b236 Reviewed-on: https://gerrit.libreoffice.org/66620 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'hwpfilter/source')
-rw-r--r--hwpfilter/source/hfont.cxx4
-rw-r--r--hwpfilter/source/hstyle.cxx13
2 files changed, 15 insertions, 2 deletions
diff --git a/hwpfilter/source/hfont.cxx b/hwpfilter/source/hfont.cxx
index e5c23a88199b..1a96b1797463 100644
--- a/hwpfilter/source/hfont.cxx
+++ b/hwpfilter/source/hfont.cxx
@@ -47,7 +47,9 @@ void HWPFont::AddFont(int lang, const char *font)
nfonts = nFonts[lang];
if (MAXFONTS <= nfonts)
return;
- strncpy(fontnames[lang].get() + FONTNAMELEN * nfonts, font, FONTNAMELEN - 1);
+ auto const p = fontnames[lang].get() + FONTNAMELEN * nfonts;
+ strncpy(p, font, FONTNAMELEN - 1);
+ p[FONTNAMELEN - 1] = '\0'; // just in case, even though the array is zero-initialized
nFonts[lang]++;
}
diff --git a/hwpfilter/source/hstyle.cxx b/hwpfilter/source/hstyle.cxx
index cc3ef07cc987..87fd1efbe978 100644
--- a/hwpfilter/source/hstyle.cxx
+++ b/hwpfilter/source/hstyle.cxx
@@ -66,7 +66,18 @@ void HWPStyle::SetName(int n, char const *name)
if (n >= 0 && n < nstyles)
{
if (name)
- strncpy(DATA[n].name, name, MAXSTYLENAME);
+ {
+#if defined __GNUC__ && __GNUC__ == 8 && __GNUC_MINOR__ == 2 && !defined __clang__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
+#endif
+ auto const p = DATA[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_MINOR__ == 2 && !defined __clang__
+#pragma GCC diagnostic pop
+#endif
+ }
else
DATA[n].name[0] = 0;
}