This commit is contained in:
blueloveTH 2024-02-01 15:14:46 +08:00
parent 151deed5bc
commit 11cd95b522

View File

@ -60,7 +60,7 @@ int utf8len(unsigned char c, bool suppress){
for(int i=0; i<size; i++){ for(int i=0; i<size; i++){
if(!isascii(data[i])){ is_ascii = false; break; } if(!isascii(data[i])){ is_ascii = false; break; }
} }
data[size] = '\0'; PK_ASSERT(data[size] == '\0');
} }
Str::Str(const Str& other): size(other.size), is_ascii(other.is_ascii) { Str::Str(const Str& other): size(other.size), is_ascii(other.is_ascii) {
@ -438,6 +438,7 @@ int utf8len(unsigned char c, bool suppress){
Str SStream::str(){ Str SStream::str(){
// after this call, the buffer is no longer valid // after this call, the buffer is no longer valid
buffer.reserve(buffer.size() + 1); // allocate one more byte for '\0' buffer.reserve(buffer.size() + 1); // allocate one more byte for '\0'
buffer[buffer.size()] = '\0'; // set '\0'
return Str(buffer.detach()); return Str(buffer.detach());
} }