* Fix set

* Fix: Fix implicite cast from size_t to uint32_t
This commit is contained in:
Kim Kulling
2025-04-08 13:14:10 +02:00
committed by GitHub
parent e27204c27a
commit 0ae66d2703

View File

@@ -303,12 +303,21 @@ struct aiString {
}
/** Copy a const char* to the aiString */
void Set(const char *sz) {
ai_int32 len = (ai_uint32)::strlen(sz);
if (len > static_cast<ai_int32>(AI_MAXLEN - 1)) {
len = static_cast<ai_int32>(AI_MAXLEN - 1);
void Set(const char *sz, size_t maxlen) {
if (sz == nullptr) {
return;
}
length = len;
size_t len = 0;
for (size_t i=0; i<maxlen; ++i) {
if (sz[i] == '\0') {
break;
}
++len;
}
if (len > AI_MAXLEN - 1) {
len = AI_MAXLEN - 1;
}
length = static_cast<uint32_t>(len);
memcpy(data, sz, len);
data[len] = 0;
}