[Libreoffice-commits] core.git: sax/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sun Oct 21 09:30:58 UTC 2018


 sax/source/tools/fastattribs.cxx |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

New commits:
commit 52d68e39c749de45cbec4c9114c8d10d65d45936
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Sat Oct 20 22:35:49 2018 +0200
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Oct 21 11:30:34 2018 +0200

    tdf#120703 (PVS): handle failed realloc
    
    V701 realloc() possible leak: when realloc() fails in allocating memory, original
         pointer 'mpChunk' is lost. Consider assigning realloc() to a temporary pointer.
    
    Change-Id: If85475cf22ea10e4db35532724d947e4e9005e91
    Reviewed-on: https://gerrit.libreoffice.org/62091
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sax/source/tools/fastattribs.cxx b/sax/source/tools/fastattribs.cxx
index b8d1bacec630..d7ecbc1bd13d 100644
--- a/sax/source/tools/fastattribs.cxx
+++ b/sax/source/tools/fastattribs.cxx
@@ -85,8 +85,14 @@ void FastAttributeList::add( sal_Int32 nToken, const sal_Char* pValue, size_t nV
     maAttributeValues.push_back( maAttributeValues.back() + nValueLength + 1 );
     if (maAttributeValues.back() > mnChunkLength)
     {
-        mnChunkLength = std::max(mnChunkLength * 2, maAttributeValues.back());
-        mpChunk = static_cast<sal_Char *>(realloc( mpChunk, mnChunkLength ));
+        const sal_Int32 newLen = std::max(mnChunkLength * 2, maAttributeValues.back());
+        if (auto p = static_cast<sal_Char*>(realloc(mpChunk, newLen)))
+        {
+            mnChunkLength = newLen;
+            mpChunk = p;
+        }
+        else
+            throw std::bad_alloc();
     }
     strncpy(mpChunk + nWritePosition, pValue, nValueLength);
     mpChunk[nWritePosition + nValueLength] = '\0';


More information about the Libreoffice-commits mailing list