diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-10-02 13:15:40 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-10-02 19:15:00 +0200 |
commit | 897192f07c1f7863a50e09cdd29e6631550b83ff (patch) | |
tree | d1de0e333f23989054257975baf8787a29a56b74 | |
parent | c6a7e0b1df5675bf728892176fc6c12f16804db3 (diff) |
simplify JsonWriter::reallocBuffer by using realloc
instead of malloc and copy.
spotted by mmeeks
Change-Id: Ibac83be597cfaf61f783a265562c5102bbaf29d8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122995
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | tools/source/misc/json_writer.cxx | 5 |
1 files changed, 1 insertions, 4 deletions
diff --git a/tools/source/misc/json_writer.cxx b/tools/source/misc/json_writer.cxx index b6482329ea55..f002ddc391aa 100644 --- a/tools/source/misc/json_writer.cxx +++ b/tools/source/misc/json_writer.cxx @@ -413,10 +413,7 @@ void JsonWriter::reallocBuffer(int noMoreBytesRequired) { int currentUsed = mPos - mpBuffer; auto newSize = std::max<int>(mSpaceAllocated * 2, (currentUsed + noMoreBytesRequired) * 2); - char* pNew = static_cast<char*>(malloc(newSize)); - memcpy(pNew, mpBuffer, currentUsed); - free(mpBuffer); - mpBuffer = pNew; + mpBuffer = static_cast<char*>(realloc(mpBuffer, newSize)); mPos = mpBuffer + currentUsed; mSpaceAllocated = newSize; } |