mirror of
https://github.com/qpdf/qpdf.git
synced 2025-01-31 10:58:25 +00:00
Add QUtil::make_shared_array to help with PointerHolder transition
This commit is contained in:
parent
cfaae47dc6
commit
df2f5c6a36
@ -165,6 +165,15 @@ namespace QUtil
|
||||
QPDF_DLL
|
||||
std::unique_ptr<char[]> make_unique_cstr(std::string const&);
|
||||
|
||||
// Create a shared pointer to an array. From c++20,
|
||||
// std::make_shared<T[]>(n) does this.
|
||||
template <typename T>
|
||||
std::shared_ptr<T>
|
||||
make_shared_array(size_t n)
|
||||
{
|
||||
return std::shared_ptr<T>(new T[n], std::default_delete<T[]>());
|
||||
}
|
||||
|
||||
// Returns lower-case hex-encoded version of the string, treating
|
||||
// each character in the input string as unsigned. The output
|
||||
// string will be twice as long as the input string.
|
||||
|
@ -299,9 +299,8 @@ QPDFArgParser::handleArgFileArguments()
|
||||
QUtil::make_shared_cstr(this->m->argv[i]));
|
||||
}
|
||||
}
|
||||
this->m->argv_ph = std::shared_ptr<char const*>(
|
||||
new char const*[1 + this->m->new_argv.size()],
|
||||
std::default_delete<char const*[]>());
|
||||
this->m->argv_ph = QUtil::make_shared_array<char const*>(
|
||||
1 + this->m->new_argv.size());
|
||||
for (size_t i = 0; i < this->m->new_argv.size(); ++i)
|
||||
{
|
||||
this->m->argv_ph.get()[i] = this->m->new_argv.at(i).get();
|
||||
@ -404,9 +403,8 @@ QPDFArgParser::handleBashArguments()
|
||||
}
|
||||
// Explicitly discard any non-space-terminated word. The "current
|
||||
// word" is handled specially.
|
||||
this->m->bash_argv_ph = std::shared_ptr<char const*>(
|
||||
new char const*[1 + this->m->bash_argv.size()],
|
||||
std::default_delete<char const*[]>());
|
||||
this->m->bash_argv_ph = QUtil::make_shared_array<char const*>(
|
||||
1 + this->m->bash_argv.size());
|
||||
for (size_t i = 0; i < this->m->bash_argv.size(); ++i)
|
||||
{
|
||||
this->m->bash_argv_ph.get()[i] = this->m->bash_argv.at(i).get();
|
||||
|
@ -735,9 +735,7 @@ QUtil::copy_string(std::string const& str)
|
||||
std::shared_ptr<char>
|
||||
QUtil::make_shared_cstr(std::string const& str)
|
||||
{
|
||||
auto result = std::shared_ptr<char>(
|
||||
new char[str.length() + 1],
|
||||
std::default_delete<char[]>());
|
||||
auto result = QUtil::make_shared_array<char>(str.length() + 1);
|
||||
// Use memcpy in case string contains nulls
|
||||
result.get()[str.length()] = '\0';
|
||||
memcpy(result.get(), str.c_str(), str.length());
|
||||
|
Loading…
x
Reference in New Issue
Block a user