xo-stringtable2: DString: fail without ub when alloc fails
This commit is contained in:
parent
3f91dee6e7
commit
6c31b56132
1 changed files with 17 additions and 10 deletions
|
|
@ -26,14 +26,16 @@ namespace xo {
|
|||
void * mem = mm.alloc(typeseq::id<DString>(),
|
||||
sizeof(DString) + cap);
|
||||
|
||||
result = new (mem) DString();
|
||||
if (mem) {
|
||||
result = new (mem) DString();
|
||||
|
||||
assert(result);
|
||||
assert(result);
|
||||
|
||||
result->capacity_ = cap;
|
||||
result->size_ = 0;
|
||||
if (cap > 0) {
|
||||
result->chars_[0] = '\0';
|
||||
result->capacity_ = cap;
|
||||
result->size_ = 0;
|
||||
if (cap > 0) {
|
||||
result->chars_[0] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -50,10 +52,15 @@ namespace xo {
|
|||
void * mem = mm.alloc(typeseq::id<DString>(),
|
||||
sizeof(DString) + cap);
|
||||
|
||||
DString * result = new (mem) DString();
|
||||
result->capacity_ = cap;
|
||||
result->size_ = len;
|
||||
std::memcpy(result->chars_, cstr, cap);
|
||||
DString * result = nullptr;
|
||||
|
||||
if (mem) {
|
||||
result = new (mem) DString();
|
||||
result->capacity_ = cap;
|
||||
result->size_ = len;
|
||||
|
||||
std::memcpy(result->chars_, cstr, cap);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue