NULL check after malloc

This commit is contained in:
Scott Giese
2021-02-13 22:25:31 -06:00
parent 469a28c49a
commit d1509d6096
3 changed files with 14 additions and 8 deletions
+4 -2
View File
@@ -67,8 +67,10 @@ void BufferedLogCallback::operator()(sgDebugClass c, sgDebugPriority p,
vector_cstring::value_type msg;
if (aMessage.size() >= d->m_maxLength) {
msg = (vector_cstring::value_type) malloc(d->m_maxLength);
strncpy((char*) msg, aMessage.c_str(), d->m_maxLength - 1);
msg[d->m_maxLength - 1] = 0; // add final NULL byte
if (msg) {
strncpy((char*) msg, aMessage.c_str(), d->m_maxLength - 1);
msg[d->m_maxLength - 1] = 0; // add final NULL byte
}
} else {
msg = (vector_cstring::value_type) strdup(aMessage.c_str());
}