[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - tools/source

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Fri Jun 19 19:48:42 UTC 2020


 tools/source/misc/json_writer.cxx |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

New commits:
commit b3155a3bf5c906ce6653504f6612e84fa7140068
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Thu Jun 18 11:29:41 2020 +0200
Commit:     Aron Budea <aron.budea at collabora.com>
CommitDate: Fri Jun 19 21:48:09 2020 +0200

    Avoid unhelpful -Werror=stringop-truncation
    
    ...emitted at least by recent GCC 11 trunk (even with --disable-optimized, where
    optimization level traditionally has some impact on what warnings of this kind
    are emitted exactly):
    
    > tools/source/misc/json_writer.cxx: In member function ‘tools::ScopedJsonWriterNode tools::JsonWriter::startNode(const char*)’:
    > tools/source/misc/json_writer.cxx:42:12: error: ‘char* strncpy(char*, const char*, size_t)’ output truncated before terminating nul copying 5 bytes from a string of the same length [-Werror=stringop-truncation]
    >    42 |     strncpy(mPos, "\": { ", 5);
    >       |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
    
    etc.
    
    Change-Id: Id96964b178b61879cf2373c5b418f5c9df4a226f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96593
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Reviewed-by: Justin Luth <justin_luth at sil.org>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit de32eb539bbcf291f9968ae12696e1317fdb855d)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96749
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Aron Budea <aron.budea at collabora.com>

diff --git a/tools/source/misc/json_writer.cxx b/tools/source/misc/json_writer.cxx
index 5bba05a4c21d..3040fda8a080 100644
--- a/tools/source/misc/json_writer.cxx
+++ b/tools/source/misc/json_writer.cxx
@@ -43,7 +43,7 @@ ScopedJsonWriterNode JsonWriter::startNode(const char* pNodeName)
     ++mPos;
     memcpy(mPos, pNodeName, len);
     mPos += len;
-    strncpy(mPos, "\": { ", 5);
+    memcpy(mPos, "\": { ", 5);
     mPos += 5;
     mStartNodeCount++;
     mbFirstFieldInNode = true;
@@ -70,7 +70,7 @@ void JsonWriter::put(const char* pPropName, const OUString& rPropVal)
     ++mPos;
     memcpy(mPos, pPropName, nPropNameLength);
     mPos += nPropNameLength;
-    strncpy(mPos, "\": \"", 4);
+    memcpy(mPos, "\": \"", 4);
     mPos += 4;
 
     // Convert from UTF-16 to UTF-8 and perform escaping
@@ -129,7 +129,7 @@ void JsonWriter::put(const char* pPropName, const OString& rPropVal)
     ++mPos;
     memcpy(mPos, pPropName, nPropNameLength);
     mPos += nPropNameLength;
-    strncpy(mPos, "\": \"", 4);
+    memcpy(mPos, "\": \"", 4);
     mPos += 4;
 
     // copy and perform escaping
@@ -173,7 +173,7 @@ void JsonWriter::put(const char* pPropName, const char* pPropVal)
     ++mPos;
     memcpy(mPos, pPropName, nPropNameLength);
     mPos += nPropNameLength;
-    strncpy(mPos, "\": \"", 4);
+    memcpy(mPos, "\": \"", 4);
     mPos += 4;
 
     // copy and perform escaping
@@ -219,7 +219,7 @@ void JsonWriter::put(const char* pPropName, int nPropVal)
     ++mPos;
     memcpy(mPos, pPropName, nPropNameLength);
     mPos += nPropNameLength;
-    strncpy(mPos, "\": ", 3);
+    memcpy(mPos, "\": ", 3);
     mPos += 3;
 
     mPos += sprintf(mPos, "%d", nPropVal);


More information about the Libreoffice-commits mailing list