3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-06-06 22:23:22 +00:00

fix a couple hundred deref-after-free bugs due to .c_str() on a temporary string

This commit is contained in:
Nuno Lopes 2020-07-11 20:24:45 +01:00
parent 48a9defb0d
commit 23e6adcad3
64 changed files with 248 additions and 229 deletions

View file

@ -78,6 +78,16 @@ public:
m_pos += len;
}
void append(const std::string &str) {
size_t len = str.size();
size_t new_pos = m_pos + len;
while (new_pos > m_capacity) {
expand();
}
memcpy(m_buffer + m_pos, str.c_str(), len);
m_pos += len;
}
void append(int n) {
auto str = std::to_string(n);
append(str.c_str());
@ -121,6 +131,12 @@ inline string_buffer<SZ> & operator<<(string_buffer<SZ> & buffer, const char * s
return buffer;
}
template<unsigned SZ>
inline string_buffer<SZ> & operator<<(string_buffer<SZ> & buffer, const std::string &str) {
buffer.append(str);
return buffer;
}
template<unsigned SZ>
inline string_buffer<SZ> & operator<<(string_buffer<SZ> & buffer, char c) {
buffer.append(c);