Draft: Update init of aiString (#5623)

* Draft: Update init of aiString

- closes https://github.com/assimp/assimp/issues/5622

* Update types.h

* Fix typo

* Fix another typo

* Adapt usage of AI_MAXLEN

* Fix compare operator

* Add missing renames
pull/5625/head^2
Kim Kulling 2024-06-17 13:12:54 +02:00 committed by GitHub
parent 75091d4529
commit a51500ba2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 104 additions and 93 deletions

View File

@ -709,7 +709,7 @@ void Discreet3DSImporter::GenerateNodeGraph(aiScene *pcOut) {
pcNode->mNumMeshes = 1; pcNode->mNumMeshes = 1;
// Build a name for the node // Build a name for the node
pcNode->mName.length = ai_snprintf(pcNode->mName.data, MAXLEN, "3DSMesh_%u", i); pcNode->mName.length = ai_snprintf(pcNode->mName.data, AI_MAXLEN, "3DSMesh_%u", i);
} }
// Build dummy nodes for all cameras // Build dummy nodes for all cameras

View File

@ -193,7 +193,7 @@ bool AC3DImporter::LoadObjectSection(std::vector<Object> &objects) {
// Generate a default name for both the light source and the node // Generate a default name for both the light source and the node
// FIXME - what's the right way to print a size_t? Is 'zu' universally available? stick with the safe version. // FIXME - what's the right way to print a size_t? Is 'zu' universally available? stick with the safe version.
light->mName.length = ::ai_snprintf(light->mName.data, MAXLEN, "ACLight_%i", static_cast<unsigned int>(mLights->size()) - 1); light->mName.length = ::ai_snprintf(light->mName.data, AI_MAXLEN, "ACLight_%i", static_cast<unsigned int>(mLights->size()) - 1);
obj.name = std::string(light->mName.data); obj.name = std::string(light->mName.data);
ASSIMP_LOG_VERBOSE_DEBUG("AC3D: Light source encountered"); ASSIMP_LOG_VERBOSE_DEBUG("AC3D: Light source encountered");
@ -696,18 +696,18 @@ aiNode *AC3DImporter::ConvertObjectSection(Object &object,
// generate a name depending on the type of the node // generate a name depending on the type of the node
switch (object.type) { switch (object.type) {
case Object::Group: case Object::Group:
node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACGroup_%i", mGroupsCounter++); node->mName.length = ::ai_snprintf(node->mName.data, AI_MAXLEN, "ACGroup_%i", mGroupsCounter++);
break; break;
case Object::Poly: case Object::Poly:
node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACPoly_%i", mPolysCounter++); node->mName.length = ::ai_snprintf(node->mName.data, AI_MAXLEN, "ACPoly_%i", mPolysCounter++);
break; break;
case Object::Light: case Object::Light:
node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACLight_%i", mLightsCounter++); node->mName.length = ::ai_snprintf(node->mName.data, AI_MAXLEN, "ACLight_%i", mLightsCounter++);
break; break;
// there shouldn't be more than one world, but we don't care // there shouldn't be more than one world, but we don't care
case Object::World: case Object::World:
node->mName.length = ::ai_snprintf(node->mName.data, MAXLEN, "ACWorld_%i", mWorldsCounter++); node->mName.length = ::ai_snprintf(node->mName.data, AI_MAXLEN, "ACWorld_%i", mWorldsCounter++);
break; break;
} }
} }

View File

@ -359,7 +359,7 @@ void BlenderImporter::ResolveImage(aiMaterial *out, const Material *mat, const M
// check if the file contents are bundled with the BLEND file // check if the file contents are bundled with the BLEND file
if (img->packedfile) { if (img->packedfile) {
name.data[0] = '*'; name.data[0] = '*';
name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(MAXLEN - 1), static_cast<int32_t>(conv_data.textures->size())); name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(AI_MAXLEN - 1), static_cast<int32_t>(conv_data.textures->size()));
conv_data.textures->push_back(new aiTexture()); conv_data.textures->push_back(new aiTexture());
aiTexture *curTex = conv_data.textures->back(); aiTexture *curTex = conv_data.textures->back();
@ -433,7 +433,7 @@ void BlenderImporter::AddSentinelTexture(aiMaterial *out, const Material *mat, c
(void)conv_data; (void)conv_data;
aiString name; aiString name;
name.length = ai_snprintf(name.data, MAXLEN, "Procedural,num=%i,type=%s", conv_data.sentinel_cnt++, name.length = ai_snprintf(name.data, AI_MAXLEN, "Procedural,num=%i,type=%s", conv_data.sentinel_cnt++,
GetTextureTypeDisplayString(tex->tex->type)); GetTextureTypeDisplayString(tex->tex->type));
out->AddProperty(&name, AI_MATKEY_TEXTURE_DIFFUSE( out->AddProperty(&name, AI_MATKEY_TEXTURE_DIFFUSE(
conv_data.next_texture[aiTextureType_DIFFUSE]++)); conv_data.next_texture[aiTextureType_DIFFUSE]++));

View File

@ -1860,7 +1860,7 @@ aiString FBXConverter::GetTexturePath(const Texture *tex) {
// We need to load all textures before referencing them, as FBX file format order may reference a texture before loading it // We need to load all textures before referencing them, as FBX file format order may reference a texture before loading it
// This may occur on this case too, it has to be studied // This may occur on this case too, it has to be studied
path.data[0] = '*'; path.data[0] = '*';
path.length = 1 + ASSIMP_itoa10(path.data + 1, MAXLEN - 1, index); path.length = 1 + ASSIMP_itoa10(path.data + 1, AI_MAXLEN - 1, index);
} }
} }
} }
@ -2440,7 +2440,7 @@ void FBXConverter::SetShadingPropertiesRaw(aiMaterial *out_mat, const PropertyTa
// setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture) // setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture)
path.data[0] = '*'; path.data[0] = '*';
path.length = 1 + ASSIMP_itoa10(path.data + 1, MAXLEN - 1, index); path.length = 1 + ASSIMP_itoa10(path.data + 1, AI_MAXLEN - 1, index);
} }
out_mat->AddProperty(&path, (name + "|file").c_str(), aiTextureType_UNKNOWN, 0); out_mat->AddProperty(&path, (name + "|file").c_str(), aiTextureType_UNKNOWN, 0);
@ -2806,7 +2806,7 @@ void FBXConverter::ProcessMorphAnimDatas(std::map<std::string, morphAnimData *>
auto geoIt = std::find(model->GetGeometry().begin(), model->GetGeometry().end(), geo); auto geoIt = std::find(model->GetGeometry().begin(), model->GetGeometry().end(), geo);
auto geoIndex = static_cast<unsigned int>(std::distance(model->GetGeometry().begin(), geoIt)); auto geoIndex = static_cast<unsigned int>(std::distance(model->GetGeometry().begin(), geoIt));
auto name = aiString(FixNodeName(model->Name() + "*")); auto name = aiString(FixNodeName(model->Name() + "*"));
name.length = 1 + ASSIMP_itoa10(name.data + name.length, MAXLEN - 1, geoIndex); name.length = 1 + ASSIMP_itoa10(name.data + name.length, AI_MAXLEN - 1, geoIndex);
morphAnimData *animData; morphAnimData *animData;
auto animIt = morphAnimDatas->find(name.C_Str()); auto animIt = morphAnimDatas->find(name.C_Str());
if (animIt == morphAnimDatas->end()) { if (animIt == morphAnimDatas->end()) {

View File

@ -134,7 +134,7 @@ public:
const char* elementNameCStr = elementName.c_str(); const char* elementNameCStr = elementName.c_str();
for (auto element = elements.begin(); element != elements.end(); ++element) for (auto element = elements.begin(); element != elements.end(); ++element)
{ {
if (!ASSIMP_strincmp(element->first.c_str(), elementNameCStr, MAXLEN)) { if (!ASSIMP_strincmp(element->first.c_str(), elementNameCStr, AI_MAXLEN)) {
return element->second; return element->second;
} }
} }

View File

@ -168,7 +168,7 @@ void IRRImporter::BuildSkybox(std::vector<aiMesh *> &meshes, std::vector<aiMater
aiMaterial *out = (aiMaterial *)(*(materials.end() - (6 - i))); aiMaterial *out = (aiMaterial *)(*(materials.end() - (6 - i)));
aiString s; aiString s;
s.length = ::ai_snprintf(s.data, MAXLEN, "SkyboxSide_%u", i); s.length = ::ai_snprintf(s.data, AI_MAXLEN, "SkyboxSide_%u", i);
out->AddProperty(&s, AI_MATKEY_NAME); out->AddProperty(&s, AI_MATKEY_NAME);
int shading = aiShadingMode_NoShading; int shading = aiShadingMode_NoShading;
@ -316,7 +316,7 @@ void IRRImporter::ComputeAnimations(Node *root, aiNode *real, std::vector<aiNode
if (cur != total - 1) { if (cur != total - 1) {
// Build a new name - a prefix instead of a suffix because it is // Build a new name - a prefix instead of a suffix because it is
// easier to check against // easier to check against
anim->mNodeName.length = ::ai_snprintf(anim->mNodeName.data, MAXLEN, anim->mNodeName.length = ::ai_snprintf(anim->mNodeName.data, AI_MAXLEN,
"$INST_DUMMY_%i_%s", total - 1, "$INST_DUMMY_%i_%s", total - 1,
(root->name.length() ? root->name.c_str() : "")); (root->name.length() ? root->name.c_str() : ""));

View File

@ -305,14 +305,14 @@ void LWSImporter::SetupNodeName(aiNode *nd, LWS::NodeDesc &src) {
} }
std::string::size_type t = src.path.substr(s).find_last_of('.'); std::string::size_type t = src.path.substr(s).find_last_of('.');
nd->mName.length = ::ai_snprintf(nd->mName.data, MAXLEN, "%s_(%08X)", src.path.substr(s).substr(0, t).c_str(), combined); nd->mName.length = ::ai_snprintf(nd->mName.data, AI_MAXLEN, "%s_(%08X)", src.path.substr(s).substr(0, t).c_str(), combined);
if (nd->mName.length > MAXLEN) { if (nd->mName.length > AI_MAXLEN) {
nd->mName.length = MAXLEN; nd->mName.length = AI_MAXLEN;
} }
return; return;
} }
} }
nd->mName.length = ::ai_snprintf(nd->mName.data, MAXLEN, "%s_(%08X)", src.name, combined); nd->mName.length = ::ai_snprintf(nd->mName.data, AI_MAXLEN, "%s_(%08X)", src.name, combined);
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------

View File

@ -707,7 +707,7 @@ void MD5Importer::LoadMD5CameraFile() {
for (std::vector<unsigned int>::const_iterator it = cuts.begin(); it != cuts.end() - 1; ++it) { for (std::vector<unsigned int>::const_iterator it = cuts.begin(); it != cuts.end() - 1; ++it) {
aiAnimation *anim = *tmp++ = new aiAnimation(); aiAnimation *anim = *tmp++ = new aiAnimation();
anim->mName.length = ::ai_snprintf(anim->mName.data, MAXLEN, "anim%u_from_%u_to_%u", (unsigned int)(it - cuts.begin()), (*it), *(it + 1)); anim->mName.length = ::ai_snprintf(anim->mName.data, AI_MAXLEN, "anim%u_from_%u_to_%u", (unsigned int)(it - cuts.begin()), (*it), *(it + 1));
anim->mTicksPerSecond = cameraParser.fFrameRate; anim->mTicksPerSecond = cameraParser.fFrameRate;
anim->mChannels = new aiNodeAnim *[anim->mNumChannels = 1]; anim->mChannels = new aiNodeAnim *[anim->mNumChannels = 1];

View File

@ -962,7 +962,7 @@ void MDLImporter::CalcAbsBoneMatrices_3DGS_MDL7(MDL::IntBone_MDL7 **apcOutBones)
if (AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE == pcHeader->bone_stc_size) { if (AI_MDL7_BONE_STRUCT_SIZE__NAME_IS_NOT_THERE == pcHeader->bone_stc_size) {
// no real name for our poor bone is specified :-( // no real name for our poor bone is specified :-(
pcOutBone->mName.length = ai_snprintf(pcOutBone->mName.data, MAXLEN, pcOutBone->mName.length = ai_snprintf(pcOutBone->mName.data, AI_MAXLEN,
"UnnamedBone_%i", iBone); "UnnamedBone_%i", iBone);
} else { } else {
// Make sure we won't run over the buffer's end if there is no // Make sure we won't run over the buffer's end if there is no
@ -1567,7 +1567,7 @@ void MDLImporter::InternReadFile_3DGS_MDL7() {
} else { } else {
pcNode->mName.length = (ai_uint32)::strlen(szBuffer); pcNode->mName.length = (ai_uint32)::strlen(szBuffer);
} }
::strncpy(pcNode->mName.data, szBuffer, MAXLEN - 1); ::strncpy(pcNode->mName.data, szBuffer, AI_MAXLEN - 1);
++p; ++p;
} }
} }

View File

@ -494,7 +494,7 @@ void MDLImporter::ParseSkinLump_3DGS_MDL7(
aiString szFile; aiString szFile;
const size_t iLen = strlen((const char *)szCurrent); const size_t iLen = strlen((const char *)szCurrent);
size_t iLen2 = iLen > (MAXLEN - 1) ? (MAXLEN - 1) : iLen; size_t iLen2 = iLen > (AI_MAXLEN - 1) ? (AI_MAXLEN - 1) : iLen;
memcpy(szFile.data, (const char *)szCurrent, iLen2); memcpy(szFile.data, (const char *)szCurrent, iLen2);
szFile.data[iLen2] = '\0'; szFile.data[iLen2] = '\0';
szFile.length = static_cast<ai_uint32>(iLen2); szFile.length = static_cast<ai_uint32>(iLen2);

View File

@ -588,7 +588,7 @@ bool Q3BSPFileImporter::importTextureFromArchive(const Q3BSP::Q3BSPModel *model,
aiString name; aiString name;
name.data[0] = '*'; name.data[0] = '*';
name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(MAXLEN - 1), static_cast<int32_t>(mTextures.size())); name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(AI_MAXLEN - 1), static_cast<int32_t>(mTextures.size()));
archive->Close(pTextureStream); archive->Close(pTextureStream);
@ -641,7 +641,7 @@ bool Q3BSPFileImporter::importLightmap(const Q3BSP::Q3BSPModel *pModel, aiScene
aiString name; aiString name;
name.data[0] = '*'; name.data[0] = '*';
name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(MAXLEN - 1), static_cast<int32_t>(mTextures.size())); name.length = 1 + ASSIMP_itoa10(name.data + 1, static_cast<unsigned int>(AI_MAXLEN - 1), static_cast<int32_t>(mTextures.size()));
pMatHelper->AddProperty(&name, AI_MATKEY_TEXTURE_LIGHTMAP(1)); pMatHelper->AddProperty(&name, AI_MATKEY_TEXTURE_LIGHTMAP(1));
mTextures.push_back(pTexture); mTextures.push_back(pTexture);

View File

@ -250,7 +250,7 @@ void Q3DImporter::InternReadFile(const std::string &pFile,
c = stream.GetI1(); c = stream.GetI1();
while (c) { while (c) {
mat.name.data[mat.name.length++] = c; mat.name.data[mat.name.length++] = c;
if (mat.name.length == MAXLEN) { if (mat.name.length == AI_MAXLEN) {
ASSIMP_LOG_ERROR("String ouverflow detected, skipped material name parsing."); ASSIMP_LOG_ERROR("String ouverflow detected, skipped material name parsing.");
break; break;
} }

View File

@ -589,12 +589,12 @@ void SMDImporter::CreateOutputMaterials() {
pScene->mMaterials[iMat] = pcMat; pScene->mMaterials[iMat] = pcMat;
aiString szName; aiString szName;
szName.length = static_cast<ai_uint32>(ai_snprintf(szName.data,MAXLEN,"Texture_%u",iMat)); szName.length = static_cast<ai_uint32>(ai_snprintf(szName.data, AI_MAXLEN, "Texture_%u", iMat));
pcMat->AddProperty(&szName,AI_MATKEY_NAME); pcMat->AddProperty(&szName,AI_MATKEY_NAME);
if (aszTextures[iMat].length()) if (aszTextures[iMat].length())
{ {
::strncpy(szName.data, aszTextures[iMat].c_str(),MAXLEN-1); ::strncpy(szName.data, aszTextures[iMat].c_str(), AI_MAXLEN - 1);
szName.length = static_cast<ai_uint32>( aszTextures[iMat].length() ); szName.length = static_cast<ai_uint32>( aszTextures[iMat].length() );
pcMat->AddProperty(&szName,AI_MATKEY_TEXTURE_DIFFUSE(0)); pcMat->AddProperty(&szName,AI_MATKEY_TEXTURE_DIFFUSE(0));
} }

View File

@ -257,7 +257,7 @@ void STLImporter::LoadASCIIFile(aiNode *root) {
size_t temp = (size_t)(sz - szMe); size_t temp = (size_t)(sz - szMe);
// setup the name of the node // setup the name of the node
if (temp) { if (temp) {
if (temp >= MAXLEN) { if (temp >= AI_MAXLEN) {
throw DeadlyImportError("STL: Node name too long"); throw DeadlyImportError("STL: Node name too long");
} }
std::string name(szMe, temp); std::string name(szMe, temp);

View File

@ -452,7 +452,7 @@ void UnrealImporter::InternReadFile(const std::string &pFile,
aiColor3D color(1.f, 1.f, 1.f); aiColor3D color(1.f, 1.f, 1.f);
aiString s; aiString s;
::ai_snprintf(s.data, MAXLEN, "mat%u_tx%u_", i, materials[i].tex); ::ai_snprintf(s.data, AI_MAXLEN, "mat%u_tx%u_", i, materials[i].tex);
// set the two-sided flag // set the two-sided flag
if (materials[i].type == Unreal::MF_NORMAL_TS) { if (materials[i].type == Unreal::MF_NORMAL_TS) {
@ -472,7 +472,7 @@ void UnrealImporter::InternReadFile(const std::string &pFile,
// a special name for the weapon attachment point // a special name for the weapon attachment point
if (materials[i].type == Unreal::MF_WEAPON_PLACEHOLDER) { if (materials[i].type == Unreal::MF_WEAPON_PLACEHOLDER) {
s.length = ::ai_snprintf(s.data, MAXLEN, "$WeaponTag$"); s.length = ::ai_snprintf(s.data, AI_MAXLEN, "$WeaponTag$");
color = aiColor3D(0.f, 0.f, 0.f); color = aiColor3D(0.f, 0.f, 0.f);
} }

View File

@ -109,7 +109,7 @@ inline void SetMaterialColorProperty(std::vector<int> &embeddedTexIdxs, Asset &
if (texIdx != -1) { // embedded if (texIdx != -1) { // embedded
// setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture) // setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture)
uri.data[0] = '*'; uri.data[0] = '*';
uri.length = 1 + ASSIMP_itoa10(uri.data + 1, MAXLEN - 1, texIdx); uri.length = 1 + ASSIMP_itoa10(uri.data + 1, AI_MAXLEN - 1, texIdx);
} }
mat->AddProperty(&uri, _AI_MATKEY_TEXTURE_BASE, texType, 0); mat->AddProperty(&uri, _AI_MATKEY_TEXTURE_BASE, texType, 0);
@ -242,7 +242,7 @@ void glTFImporter::ImportMeshes(glTF::Asset &r) {
if (mesh.primitives.size() > 1) { if (mesh.primitives.size() > 1) {
ai_uint32 &len = aim->mName.length; ai_uint32 &len = aim->mName.length;
aim->mName.data[len] = '-'; aim->mName.data[len] = '-';
len += 1 + ASSIMP_itoa10(aim->mName.data + len + 1, unsigned(MAXLEN - len - 1), p); len += 1 + ASSIMP_itoa10(aim->mName.data + len + 1, unsigned(AI_MAXLEN - len - 1), p);
} }
switch (prim.mode) { switch (prim.mode) {

View File

@ -161,7 +161,7 @@ static void SetMaterialTextureProperty(std::vector<int> &embeddedTexIdxs, Asset
if (texIdx != -1) { // embedded if (texIdx != -1) { // embedded
// setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture) // setup texture reference string (copied from ColladaLoader::FindFilenameForEffectTexture)
uri.data[0] = '*'; uri.data[0] = '*';
uri.length = 1 + ASSIMP_itoa10(uri.data + 1, MAXLEN - 1, texIdx); uri.length = 1 + ASSIMP_itoa10(uri.data + 1, AI_MAXLEN - 1, texIdx);
} }
mat->AddProperty(&uri, AI_MATKEY_TEXTURE(texType, texSlot)); mat->AddProperty(&uri, AI_MATKEY_TEXTURE(texType, texSlot));
@ -539,7 +539,7 @@ void glTF2Importer::ImportMeshes(glTF2::Asset &r) {
if (mesh.primitives.size() > 1) { if (mesh.primitives.size() > 1) {
ai_uint32 &len = aim->mName.length; ai_uint32 &len = aim->mName.length;
aim->mName.data[len] = '-'; aim->mName.data[len] = '-';
len += 1 + ASSIMP_itoa10(aim->mName.data + len + 1, unsigned(MAXLEN - len - 1), p); len += 1 + ASSIMP_itoa10(aim->mName.data + len + 1, unsigned(AI_MAXLEN - len - 1), p);
} }
switch (prim.mode) { switch (prim.mode) {

View File

@ -78,7 +78,7 @@ inline void PrefixString(aiString &string, const char *prefix, unsigned int len)
if (string.length >= 1 && string.data[0] == '$') if (string.length >= 1 && string.data[0] == '$')
return; return;
if (len + string.length >= MAXLEN - 1) { if (len + string.length >= AI_MAXLEN - 1) {
ASSIMP_LOG_VERBOSE_DEBUG("Can't add an unique prefix because the string is too long"); ASSIMP_LOG_VERBOSE_DEBUG("Can't add an unique prefix because the string is too long");
ai_assert(false); ai_assert(false);
return; return;
@ -408,7 +408,7 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector<At
// where n is the index of the texture. // where n is the index of the texture.
// Copy here because we overwrite the string data in-place and the buffer inside of aiString // Copy here because we overwrite the string data in-place and the buffer inside of aiString
// will be a lie if we just reinterpret from prop->mData. The size of mData is not guaranteed to be // will be a lie if we just reinterpret from prop->mData. The size of mData is not guaranteed to be
// MAXLEN in size. // AI_MAXLEN in size.
aiString s(*(aiString *)prop->mData); aiString s(*(aiString *)prop->mData);
if ('*' == s.data[0]) { if ('*' == s.data[0]) {
// Offset the index and write it back .. // Offset the index and write it back ..

View File

@ -486,7 +486,7 @@ aiReturn aiMaterial::AddBinaryProperty(const void *pInput,
memcpy(pcNew->mData, pInput, pSizeInBytes); memcpy(pcNew->mData, pInput, pSizeInBytes);
pcNew->mKey.length = static_cast<ai_uint32>(::strlen(pKey)); pcNew->mKey.length = static_cast<ai_uint32>(::strlen(pKey));
ai_assert(MAXLEN > pcNew->mKey.length); ai_assert(AI_MAXLEN > pcNew->mKey.length);
strcpy(pcNew->mKey.data, pKey); strcpy(pcNew->mKey.data, pKey);
if (UINT_MAX != iOutIndex) { if (UINT_MAX != iOutIndex) {

View File

@ -164,7 +164,7 @@ void OptimizeGraphProcess::CollectNewChildren(aiNode *nd, std::list<aiNode *> &n
++it; ++it;
} }
if (join_master && !join.empty()) { if (join_master && !join.empty()) {
join_master->mName.length = ::ai_snprintf(join_master->mName.data, MAXLEN, "$MergedNode_%u", count_merged++); join_master->mName.length = ::ai_snprintf(join_master->mName.data, AI_MAXLEN, "$MergedNode_%u", count_merged++);
unsigned int out_meshes = 0; unsigned int out_meshes = 0;
for (std::list<aiNode *>::const_iterator it = join.cbegin(); it != join.cend(); ++it) { for (std::list<aiNode *>::const_iterator it = join.cbegin(); it != join.cend(); ++it) {

View File

@ -635,7 +635,7 @@ void PretransformVertices::Execute(aiScene *pScene) {
aiNode *pcNode = new aiNode(); aiNode *pcNode = new aiNode();
*nodes = pcNode; *nodes = pcNode;
pcNode->mParent = pScene->mRootNode; pcNode->mParent = pScene->mRootNode;
pcNode->mName.length = ai_snprintf(pcNode->mName.data, MAXLEN, "light_%u", i); pcNode->mName.length = ai_snprintf(pcNode->mName.data, AI_MAXLEN, "light_%u", i);
pScene->mLights[i]->mName = pcNode->mName; pScene->mLights[i]->mName = pcNode->mName;
} }
// generate camera nodes // generate camera nodes
@ -643,7 +643,7 @@ void PretransformVertices::Execute(aiScene *pScene) {
aiNode *pcNode = new aiNode(); aiNode *pcNode = new aiNode();
*nodes = pcNode; *nodes = pcNode;
pcNode->mParent = pScene->mRootNode; pcNode->mParent = pScene->mRootNode;
pcNode->mName.length = ::ai_snprintf(pcNode->mName.data, MAXLEN, "cam_%u", i); pcNode->mName.length = ::ai_snprintf(pcNode->mName.data, AI_MAXLEN, "cam_%u", i);
pScene->mCameras[i]->mName = pcNode->mName; pScene->mCameras[i]->mName = pcNode->mName;
} }
} }

View File

@ -176,7 +176,7 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene) {
if (ppcMaterials[idx]) { if (ppcMaterials[idx]) {
aiString sz; aiString sz;
if( ppcMaterials[idx]->Get(AI_MATKEY_NAME, sz) != AI_SUCCESS ) { if( ppcMaterials[idx]->Get(AI_MATKEY_NAME, sz) != AI_SUCCESS ) {
sz.length = ::ai_snprintf(sz.data,MAXLEN,"JoinedMaterial_#%u",p); sz.length = ::ai_snprintf(sz.data, AI_MAXLEN,"JoinedMaterial_#%u",p);
((aiMaterial*)ppcMaterials[idx])->AddProperty(&sz,AI_MATKEY_NAME); ((aiMaterial*)ppcMaterials[idx])->AddProperty(&sz,AI_MATKEY_NAME);
} }
} else { } else {

View File

@ -909,9 +909,9 @@ void ValidateDSProcess::Validate(const aiNode *pNode) {
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void ValidateDSProcess::Validate(const aiString *pString) { void ValidateDSProcess::Validate(const aiString *pString) {
if (pString->length > MAXLEN) { if (pString->length > AI_MAXLEN) {
ReportError("aiString::length is too large (%u, maximum is %lu)", ReportError("aiString::length is too large (%u, maximum is %lu)",
pString->length, MAXLEN); pString->length, AI_MAXLEN);
} }
const char *sz = pString->data; const char *sz = pString->data;
while (true) { while (true) {
@ -920,7 +920,7 @@ void ValidateDSProcess::Validate(const aiString *pString) {
ReportError("aiString::data is invalid: the terminal zero is at a wrong offset"); ReportError("aiString::data is invalid: the terminal zero is at a wrong offset");
} }
break; break;
} else if (sz >= &pString->data[MAXLEN]) { } else if (sz >= &pString->data[AI_MAXLEN]) {
ReportError("aiString::data is invalid. There is no terminal character"); ReportError("aiString::data is invalid. There is no terminal character");
} }
++sz; ++sz;

View File

@ -57,9 +57,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <iomanip> #include <iomanip>
#if defined(_MSC_VER) && !defined(__clang__) #if defined(_MSC_VER) && !defined(__clang__)
#define AI_SIZEFMT "%Iu" # define AI_SIZEFMT "%Iu"
#else #else
#define AI_SIZEFMT "%zu" # define AI_SIZEFMT "%zu"
#endif #endif
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
@ -99,9 +99,9 @@ inline int ai_snprintf(char *outBuf, size_t size, const char *format, ...) {
} }
#elif defined(__MINGW32__) #elif defined(__MINGW32__)
#define ai_snprintf __mingw_snprintf # define ai_snprintf __mingw_snprintf
#else #else
#define ai_snprintf snprintf # define ai_snprintf snprintf
#endif #endif
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
@ -185,6 +185,7 @@ AI_FORCE_INLINE std::string ai_rgba2hex(int r, int g, int b, int a, bool with_he
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
/// @brief Performs a trim from start (in place) /// @brief Performs a trim from start (in place)
/// @param s string to trim. /// @param s string to trim.
// ---------------------------------------------------------------------------------
AI_FORCE_INLINE void ai_trim_left(std::string &s) { AI_FORCE_INLINE void ai_trim_left(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
return !std::isspace(ch); return !std::isspace(ch);
@ -195,7 +196,6 @@ AI_FORCE_INLINE void ai_trim_left(std::string &s) {
/// @brief Performs a trim from end (in place). /// @brief Performs a trim from end (in place).
/// @param s string to trim. /// @param s string to trim.
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------
AI_FORCE_INLINE void ai_trim_right(std::string &s) { AI_FORCE_INLINE void ai_trim_right(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
return !std::isspace(ch); return !std::isspace(ch);
@ -214,6 +214,10 @@ AI_FORCE_INLINE std::string ai_trim(std::string &s) {
return out; return out;
} }
// ---------------------------------------------------------------------------------
/// @brief Performs a to lower operation onto on single character.
/// @param in The character
/// @return the character as lower-case.
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
template <class char_t> template <class char_t>
AI_FORCE_INLINE char_t ai_tolower(char_t in) { AI_FORCE_INLINE char_t ai_tolower(char_t in) {
@ -233,6 +237,10 @@ AI_FORCE_INLINE std::string ai_tolower(const std::string &in) {
return out; return out;
} }
// ---------------------------------------------------------------------------------
/// @brief Performs a to upper operation onto on single character.
/// @param in The character
/// @return the character as upper-case.
// --------------------------------------------------------------------------------- // ---------------------------------------------------------------------------------
template <class char_t> template <class char_t>
AI_FORCE_INLINE char_t ai_toupper(char_t in) { AI_FORCE_INLINE char_t ai_toupper(char_t in) {
@ -243,6 +251,7 @@ AI_FORCE_INLINE char_t ai_toupper(char_t in) {
/// @brief Performs a ToLower-operation and return the upper-case string. /// @brief Performs a ToLower-operation and return the upper-case string.
/// @param in The incoming string. /// @param in The incoming string.
/// @return The string as uppercase. /// @return The string as uppercase.
// ---------------------------------------------------------------------------------
AI_FORCE_INLINE std::string ai_str_toupper(const std::string &in) { AI_FORCE_INLINE std::string ai_str_toupper(const std::string &in) {
std::string out(in); std::string out(in);
std::transform(out.begin(), out.end(), out.begin(), [](char c) { return ai_toupper(c); }); std::transform(out.begin(), out.end(), out.begin(), [](char c) { return ai_toupper(c); });
@ -255,6 +264,7 @@ AI_FORCE_INLINE std::string ai_str_toupper(const std::string &in) {
/// @param in The incoming string. /// @param in The incoming string.
/// @param placeholder Placeholder character, default is a question mark. /// @param placeholder Placeholder character, default is a question mark.
/// @return The string, with all non-printable characters replaced. /// @return The string, with all non-printable characters replaced.
// ---------------------------------------------------------------------------------
AI_FORCE_INLINE std::string ai_str_toprintable(const std::string &in, char placeholder = '?') { AI_FORCE_INLINE std::string ai_str_toprintable(const std::string &in, char placeholder = '?') {
std::string out(in); std::string out(in);
std::transform(out.begin(), out.end(), out.begin(), [placeholder] (unsigned char c) { std::transform(out.begin(), out.end(), out.begin(), [placeholder] (unsigned char c) {
@ -271,9 +281,9 @@ AI_FORCE_INLINE std::string ai_str_toprintable(const std::string &in, char place
/// @param placeholder Placeholder character, default is a question mark. /// @param placeholder Placeholder character, default is a question mark.
/// @return The string, with all non-printable characters replaced. Will return an /// @return The string, with all non-printable characters replaced. Will return an
/// empty string if in is null or len is <= 0. /// empty string if in is null or len is <= 0.
// ---------------------------------------------------------------------------------
AI_FORCE_INLINE std::string ai_str_toprintable(const char *in, int len, char placeholder = '?') { AI_FORCE_INLINE std::string ai_str_toprintable(const char *in, int len, char placeholder = '?') {
return (in && len > 0) ? ai_str_toprintable(std::string(in, len), placeholder) : std::string(); return (in && len > 0) ? ai_str_toprintable(std::string(in, len), placeholder) : std::string();
} }
#endif // INCLUDED_AI_STRINGUTILS_H #endif // INCLUDED_AI_STRINGUTILS_H

View File

@ -118,9 +118,9 @@ extern "C" {
/** Maximum dimension for strings, ASSIMP strings are zero terminated. */ /** Maximum dimension for strings, ASSIMP strings are zero terminated. */
#ifdef __cplusplus #ifdef __cplusplus
static const size_t MAXLEN = 1024; static const size_t AI_MAXLEN = 1024;
#else #else
#define MAXLEN 1024 #define AI_MAXLEN 1024
#endif #endif
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
@ -243,7 +243,8 @@ struct aiColor3D {
}; // !struct aiColor3D }; // !struct aiColor3D
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------
/** Represents an UTF-8 string, zero byte terminated. /**
* @brief Represents an UTF-8 string, zero byte terminated.
* *
* The character set of an aiString is explicitly defined to be UTF-8. This Unicode * The character set of an aiString is explicitly defined to be UTF-8. This Unicode
* transformation was chosen in the belief that most strings in 3d files are limited * transformation was chosen in the belief that most strings in 3d files are limited
@ -260,42 +261,40 @@ struct aiColor3D {
* UTF-8 strings to their working character set (i.e. MBCS, WideChar). * UTF-8 strings to their working character set (i.e. MBCS, WideChar).
* *
* We use this representation instead of std::string to be C-compatible. The * We use this representation instead of std::string to be C-compatible. The
* (binary) length of such a string is limited to MAXLEN characters (including the * (binary) length of such a string is limited to AI_MAXLEN characters (including the
* the terminating zero). * the terminating zero).
*/ */
struct aiString { struct aiString {
#ifdef __cplusplus #ifdef __cplusplus
/** Default constructor, the string is set to have zero length */ /** Default constructor, the string is set to have zero length */
aiString() AI_NO_EXCEPT aiString() AI_NO_EXCEPT :
: length(0) { length(0), data{'\0'} {
data[0] = '\0';
#ifdef ASSIMP_BUILD_DEBUG #ifdef ASSIMP_BUILD_DEBUG
// Debug build: overwrite the string on its full length with ESC (27) // Debug build: overwrite the string on its full length with ESC (27)
memset(data + 1, 27, MAXLEN - 1); memset(data + 1, 27, AI_MAXLEN - 1);
#endif #endif
} }
/** Copy constructor */ /** Copy constructor */
aiString(const aiString &rOther) : aiString(const aiString &rOther) :
length(rOther.length) { length(rOther.length), data{'\0'} {
// Crop the string to the maximum length // Crop the string to the maximum length
length = length >= MAXLEN ? MAXLEN - 1 : length; length = length >= AI_MAXLEN ? AI_MAXLEN - 1 : length;
memcpy(data, rOther.data, length); memcpy(data, rOther.data, length);
data[length] = '\0'; data[length] = '\0';
} }
/** Constructor from std::string */ /** Constructor from std::string */
explicit aiString(const std::string &pString) : explicit aiString(const std::string &pString) :
length((ai_uint32)pString.length()) { length((ai_uint32)pString.length()), data{'\0'} {
length = length >= MAXLEN ? MAXLEN - 1 : length; length = length >= AI_MAXLEN ? AI_MAXLEN - 1 : length;
memcpy(data, pString.c_str(), length); memcpy(data, pString.c_str(), length);
data[length] = '\0'; data[length] = '\0';
} }
/** Copy a std::string to the aiString */ /** Copy a std::string to the aiString */
void Set(const std::string &pString) { void Set(const std::string &pString) {
if (pString.length() > MAXLEN - 1) { if (pString.length() > AI_MAXLEN - 1) {
return; return;
} }
length = (ai_uint32)pString.length(); length = (ai_uint32)pString.length();
@ -306,8 +305,8 @@ struct aiString {
/** Copy a const char* to the aiString */ /** Copy a const char* to the aiString */
void Set(const char *sz) { void Set(const char *sz) {
ai_int32 len = (ai_uint32)::strlen(sz); ai_int32 len = (ai_uint32)::strlen(sz);
if (len > (ai_int32)MAXLEN - 1) { if (len > static_cast<ai_int32>(AI_MAXLEN - 1)) {
len = (ai_int32) MAXLEN - 1; len = static_cast<ai_int32>(AI_MAXLEN - 1);
} }
length = len; length = len;
memcpy(data, sz, len); memcpy(data, sz, len);
@ -321,8 +320,8 @@ struct aiString {
} }
length = rOther.length; length = rOther.length;
if (length >(MAXLEN - 1)) { if (length > (AI_MAXLEN - 1)) {
length = (ai_int32) MAXLEN - 1; length = static_cast<ai_int32>(AI_MAXLEN - 1);
} }
memcpy(data, rOther.data, length); memcpy(data, rOther.data, length);
@ -344,21 +343,24 @@ struct aiString {
/** Comparison operator */ /** Comparison operator */
bool operator==(const aiString &other) const { bool operator==(const aiString &other) const {
return (length == other.length && 0 == memcmp(data, other.data, length)); if (length == other.length) {
return memcmp(data, other.data, length) == 0;
}
return false;
} }
/** Inverse comparison operator */ /** Inverse comparison operator */
bool operator!=(const aiString &other) const { bool operator!=(const aiString &other) const {
return (length != other.length || 0 != memcmp(data, other.data, length)); return !(*this == other);
} }
/** Append a string to the string */ /** Append a string to the string */
void Append(const char *app) { void Append(const char *app) {
const ai_uint32 len = (ai_uint32)::strlen(app); const ai_uint32 len = static_cast<ai_uint32>(::strlen(app));
if (!len) { if (!len) {
return; return;
} }
if (length + len >= MAXLEN) { if (length + len >= AI_MAXLEN) {
return; return;
} }
@ -373,7 +375,7 @@ struct aiString {
#ifdef ASSIMP_BUILD_DEBUG #ifdef ASSIMP_BUILD_DEBUG
// Debug build: overwrite the string on its full length with ESC (27) // Debug build: overwrite the string on its full length with ESC (27)
memset(data + 1, 27, MAXLEN - 1); memset(data + 1, 27, AI_MAXLEN - 1);
#endif #endif
} }
@ -389,8 +391,8 @@ struct aiString {
* the number of bytes from the beginning of the string to its end.*/ * the number of bytes from the beginning of the string to its end.*/
ai_uint32 length; ai_uint32 length;
/** String buffer. Size limit is MAXLEN */ /** String buffer. Size limit is AI_MAXLEN */
char data[MAXLEN]; char data[AI_MAXLEN];
}; // !struct aiString }; // !struct aiString
// ---------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------

View File

@ -68,7 +68,7 @@ void AddNodes(unsigned int num, aiNode *father, unsigned int depth) {
for (unsigned int i = 0; i < 5; ++i) { for (unsigned int i = 0; i < 5; ++i) {
aiNode *nd = father->mChildren[i] = new aiNode(); aiNode *nd = father->mChildren[i] = new aiNode();
nd->mName.length = snprintf(nd->mName.data, MAXLEN, "%i%i", depth, i); nd->mName.length = snprintf(nd->mName.data, AI_MAXLEN, "%i%i", depth, i);
// spawn two meshes // spawn two meshes
nd->mMeshes = new unsigned int[nd->mNumMeshes = 2]; nd->mMeshes = new unsigned int[nd->mNumMeshes = 2];

View File

@ -174,7 +174,7 @@ int CDisplay::AddNodeToDisplayList(
ai_assert(nullptr != pcNode); ai_assert(nullptr != pcNode);
ai_assert(nullptr != hRoot); ai_assert(nullptr != hRoot);
char chTemp[MAXLEN]; char chTemp[AI_MAXLEN];
if(0 == pcNode->mName.length) { if(0 == pcNode->mName.length) {
if (iIndex >= 100) { if (iIndex >= 100) {
@ -186,12 +186,12 @@ int CDisplay::AddNodeToDisplayList(
} }
else else
iIndex += iDepth * 10; iIndex += iDepth * 10;
ai_snprintf(chTemp, MAXLEN,"Node %u",iIndex); ai_snprintf(chTemp,AI_MAXLEN,"Node %u",iIndex);
} }
else { else {
ai_snprintf(chTemp, MAXLEN,"%s",pcNode->mName.data); ai_snprintf(chTemp, AI_MAXLEN, "%s", pcNode->mName.data);
} }
ai_snprintf(chTemp+strlen(chTemp), MAXLEN- strlen(chTemp), iIndex ? " (%i)" : " (%i meshes)",pcNode->mNumMeshes); ai_snprintf(chTemp + strlen(chTemp), AI_MAXLEN - strlen(chTemp), iIndex ? " (%i)" : " (%i meshes)", pcNode->mNumMeshes);
TVITEMEXW tvi; TVITEMEXW tvi;
TVINSERTSTRUCTW sNew; TVINSERTSTRUCTW sNew;
@ -236,15 +236,15 @@ int CDisplay::AddMeshToDisplayList(unsigned int iIndex, HTREEITEM hRoot)
{ {
aiMesh* pcMesh = g_pcAsset->pcScene->mMeshes[iIndex]; aiMesh* pcMesh = g_pcAsset->pcScene->mMeshes[iIndex];
char chTemp[MAXLEN]; char chTemp[AI_MAXLEN];
if(0 == pcMesh->mName.length) { if(0 == pcMesh->mName.length) {
ai_snprintf(chTemp,MAXLEN,"Mesh %u",iIndex); ai_snprintf(chTemp, AI_MAXLEN, "Mesh %u", iIndex);
} }
else { else {
ai_snprintf(chTemp,MAXLEN,"%s",pcMesh->mName.data); ai_snprintf(chTemp, AI_MAXLEN, "%s", pcMesh->mName.data);
} }
ai_snprintf(chTemp+strlen(chTemp),MAXLEN-strlen(chTemp), iIndex ? " (%i)" : " (%i faces)",pcMesh->mNumFaces); ai_snprintf(chTemp + strlen(chTemp), AI_MAXLEN - strlen(chTemp), iIndex ? " (%i)" : " (%i faces)", pcMesh->mNumFaces);
TVITEMEXW tvi; TVITEMEXW tvi;
TVINSERTSTRUCTW sNew; TVINSERTSTRUCTW sNew;
@ -280,8 +280,7 @@ int CDisplay::AddMeshToDisplayList(unsigned int iIndex, HTREEITEM hRoot)
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
// Replace the currently selected texture by another one // Replace the currently selected texture by another one
int CDisplay::ReplaceCurrentTexture(const char* szPath) int CDisplay::ReplaceCurrentTexture(const char* szPath) {
{
ai_assert(nullptr != szPath); ai_assert(nullptr != szPath);
// well ... try to load it // well ... try to load it

View File

@ -281,7 +281,7 @@ bool CMaterialManager::TryLongerPath(char* szTemp,aiString* p_szString)
// copy the result string back to the aiString // copy the result string back to the aiString
const size_t iLen = strlen(szTempB); const size_t iLen = strlen(szTempB);
size_t iLen2 = iLen+1; size_t iLen2 = iLen+1;
iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2; iLen2 = iLen2 > AI_MAXLEN ? AI_MAXLEN : iLen2;
memcpy(p_szString->data,szTempB,iLen2); memcpy(p_szString->data,szTempB,iLen2);
p_szString->length = static_cast<ai_uint32>(iLen); p_szString->length = static_cast<ai_uint32>(iLen);
return true; return true;
@ -295,7 +295,7 @@ bool CMaterialManager::TryLongerPath(char* szTemp,aiString* p_szString)
// copy the result string back to the aiString // copy the result string back to the aiString
const size_t iLen = strlen(szTempB); const size_t iLen = strlen(szTempB);
size_t iLen2 = iLen+1; size_t iLen2 = iLen+1;
iLen2 = iLen2 > MAXLEN ? MAXLEN : iLen2; iLen2 = iLen2 > AI_MAXLEN ? AI_MAXLEN : iLen2;
memcpy(p_szString->data,szTempB,iLen2); memcpy(p_szString->data,szTempB,iLen2);
p_szString->length = static_cast<ai_uint32>(iLen); p_szString->length = static_cast<ai_uint32>(iLen);
return true; return true;
@ -402,7 +402,7 @@ int CMaterialManager::FindValidPath(aiString* p_szString)
// copy the result string back to the aiStr // copy the result string back to the aiStr
const size_t len = strlen(szTemp); const size_t len = strlen(szTemp);
size_t len2 = len+1; size_t len2 = len+1;
len2 = len2 > MAXLEN ? MAXLEN : len2; len2 = len2 > AI_MAXLEN ? AI_MAXLEN : len2;
memcpy(p_szString->data, szTemp, len2); memcpy(p_szString->data, szTemp, len2);
p_szString->length = static_cast<ai_uint32>(len); p_szString->length = static_cast<ai_uint32>(len);
} }

View File

@ -842,7 +842,7 @@ void OpenAsset() {
aiString sz; aiString sz;
aiGetExtensionList(&sz); aiGetExtensionList(&sz);
char szList[MAXLEN + 100]; char szList[AI_MAXLEN + 100];
strcpy(szList,"ASSIMP assets"); strcpy(szList,"ASSIMP assets");
char* szCur = szList + 14; char* szCur = szList + 14;
strcpy(szCur,sz.data); strcpy(szCur,sz.data);