xo-stringtable2: DString: fail without ub when alloc fails

This commit is contained in:
Roland Conybeare 2026-04-10 20:29:53 -04:00
commit 6c31b56132

View file

@ -26,6 +26,7 @@ namespace xo {
void * mem = mm.alloc(typeseq::id<DString>(),
sizeof(DString) + cap);
if (mem) {
result = new (mem) DString();
assert(result);
@ -36,6 +37,7 @@ namespace xo {
result->chars_[0] = '\0';
}
}
}
return result;
}
@ -50,10 +52,15 @@ namespace xo {
void * mem = mm.alloc(typeseq::id<DString>(),
sizeof(DString) + cap);
DString * result = new (mem) DString();
DString * result = nullptr;
if (mem) {
result = new (mem) DString();
result->capacity_ = cap;
result->size_ = len;
std::memcpy(result->chars_, cstr, cap);
}
return result;
}