summaryrefslogtreecommitdiff
path: root/emfio
diff options
context:
space:
mode:
authorHossein <hossein@libreoffice.org>2021-10-18 21:16:28 +0200
committerMike Kaganski <mike.kaganski@collabora.com>2021-10-25 09:08:37 +0200
commit1fd620d06d851808dc4d8dce066387b96bf43c9a (patch)
tree4b290aa01c5c412cb602e2ca7cde93207fd4db17 /emfio
parent4a8aed2940040e8b8f0db0f06cb06a757cd06a9a (diff)
Replacing std::unique_ptr<char[]>
* Replacing std::unique_ptr<char[]> with std::vector<char> * The data bytes are read into the vector internal storage * Modification of the internal storage of the vector using the pointer returned by data() is allowed by the standard C++ Standard, revision n4830, section 2.3.11.4 Data [vector.data] Returns: A pointer such that [data(), data() + size()) is a valid range. For a non-emptyvector, data() == addressof(front()). https://github.com/cplusplus/draft/blob/main/papers/n4835.pdf * It could be replaced with std::string when data is not modified Example: 6c13e5a92ed4b6a10458cd5d5741ddb3d816df4e * std::vector<char> is useful when working with C functions that get "char *" for writing data. In this case, std::string is not usable, because data() method for it returns "const char *". Change-Id: Ife6013b16a1803c3ad7b0c64aa0cb4c8cf4373ed Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123764 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'emfio')
-rw-r--r--emfio/source/reader/emfreader.cxx6
-rw-r--r--emfio/source/reader/wmfreader.cxx6
2 files changed, 6 insertions, 6 deletions
diff --git a/emfio/source/reader/emfreader.cxx b/emfio/source/reader/emfreader.cxx
index 66b281a09d33..f3b114a57c01 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -1923,9 +1923,9 @@ namespace emfio
{
if ( nLen <= ( mnEndPos - mpInputStream->Tell() ) )
{
- std::unique_ptr<char[]> pBuf(new char[ nLen ]);
- mpInputStream->ReadBytes(pBuf.get(), nLen);
- aText = OUString(pBuf.get(), nLen, GetCharSet());
+ std::vector<char> pBuf( nLen );
+ mpInputStream->ReadBytes(pBuf.data(), nLen);
+ aText = OUString(pBuf.data(), nLen, GetCharSet());
}
}
else
diff --git a/emfio/source/reader/wmfreader.cxx b/emfio/source/reader/wmfreader.cxx
index bcee84cd386d..62c5168a6bf0 100644
--- a/emfio/source/reader/wmfreader.cxx
+++ b/emfio/source/reader/wmfreader.cxx
@@ -708,9 +708,9 @@ namespace emfio
nOriginalTextLen = nOriginalBlockLen = nRemainingSize;
}
- std::unique_ptr<char[]> pChar(new char[nOriginalBlockLen]);
- mpInputStream->ReadBytes(pChar.get(), nOriginalBlockLen);
- OUString aText(pChar.get(), nOriginalTextLen, GetCharSet()); // after this conversion the text may contain
+ std::vector<char> pChar(nOriginalBlockLen);
+ mpInputStream->ReadBytes(pChar.data(), nOriginalBlockLen);
+ OUString aText(pChar.data(), nOriginalTextLen, GetCharSet()); // after this conversion the text may contain
sal_Int32 nNewTextLen = aText.getLength(); // less character (japanese version), so the
// dxAry will not fit
if ( nNewTextLen )