mirror of
https://github.com/Z3Prover/z3
synced 2025-04-29 03:45:51 +00:00
fix a couple hundred deref-after-free bugs due to .c_str() on a temporary string
This commit is contained in:
parent
48a9defb0d
commit
23e6adcad3
64 changed files with 248 additions and 229 deletions
|
@ -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);
|
||||
|
|
|
@ -20,8 +20,9 @@ Revision History:
|
|||
// include "util/new_symbol.h"
|
||||
#else
|
||||
#pragma once
|
||||
#include<ostream>
|
||||
#include<climits>
|
||||
#include <climits>
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
|
||||
#include "util/util.h"
|
||||
#include "util/tptr.h"
|
||||
|
@ -56,6 +57,7 @@ public:
|
|||
m_data(nullptr) {
|
||||
}
|
||||
explicit symbol(char const * d);
|
||||
explicit symbol(const std::string & str) : symbol(str.c_str()) {}
|
||||
explicit symbol(unsigned idx):
|
||||
m_data(BOXTAGINT(char const *, idx, 1)) {
|
||||
#if !defined(__LP64__) && !defined(_WIN64)
|
||||
|
|
|
@ -24,6 +24,7 @@ Revision History:
|
|||
#include<climits>
|
||||
#include<limits>
|
||||
#include<stdint.h>
|
||||
#include <string>
|
||||
|
||||
#ifndef SIZE_MAX
|
||||
#define SIZE_MAX std::numeric_limits<std::size_t>::max()
|
||||
|
@ -375,6 +376,7 @@ class escaped {
|
|||
char const * end() const;
|
||||
public:
|
||||
escaped(char const * str, bool trim_nl = false, unsigned indent = 0):m_str(str), m_trim_nl(trim_nl), m_indent(indent) {}
|
||||
escaped(const std::string &str, bool trim_nl = false, unsigned indent = 0):m_str(str.c_str()), m_trim_nl(trim_nl), m_indent(indent) {}
|
||||
void display(std::ostream & out) const;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue