mirror of
https://github.com/debauchee/barrier.git
synced 2025-07-19 17:37:41 +02:00
fixed: XArchEval "what" returns garbage (memory deleted).
This commit is contained in:
parent
8283955765
commit
44a98c6c9d
8 changed files with 53 additions and 90 deletions
|
@ -17,6 +17,9 @@
|
|||
|
||||
#include "base/String.h"
|
||||
|
||||
#include <memory>
|
||||
#include <cstdarg>
|
||||
|
||||
void
|
||||
find_replace_all(
|
||||
CString& subject,
|
||||
|
@ -29,3 +32,34 @@ find_replace_all(
|
|||
pos += replace.length();
|
||||
}
|
||||
}
|
||||
|
||||
CString
|
||||
string_format(const CString format, ...)
|
||||
{
|
||||
// reserve 2 times as much as the length of the format
|
||||
size_t final, n = format.size() * 2;
|
||||
|
||||
CString str;
|
||||
std::unique_ptr<char[]> formatted;
|
||||
va_list ap;
|
||||
|
||||
while (true) {
|
||||
|
||||
// wrap the plain char array in unique_ptr
|
||||
formatted.reset(new char[n]);
|
||||
|
||||
strcpy(&formatted[0], format.c_str());
|
||||
va_start(ap, format);
|
||||
final = vsnprintf(&formatted[0], n, format.c_str(), ap);
|
||||
va_end(ap);
|
||||
|
||||
if (final < 0 || final >= n) {
|
||||
n += abs(static_cast<int>(final - n + 1));
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return CString(formatted.get());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue