Remove strcpy. (#5802)
* Remove strcpy. * Sonarcube: Add more strcpy replacements * BlenderLoader: Replace strncpy by memcpy
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
---------------------------------------------------------------------------
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2024, assimp team
|
||||
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
@@ -495,8 +493,9 @@ void BlenderImporter::BuildDefaultMaterial(Blender::ConversionData &conv_data) {
|
||||
if (index == static_cast<unsigned int>(-1)) {
|
||||
// Setup a default material.
|
||||
std::shared_ptr<Material> p(new Material());
|
||||
ai_assert(::strlen(AI_DEFAULT_MATERIAL_NAME) < sizeof(p->id.name) - 2);
|
||||
strcpy(p->id.name + 2, AI_DEFAULT_MATERIAL_NAME);
|
||||
const size_t len = ::strlen(AI_DEFAULT_MATERIAL_NAME);
|
||||
ai_assert(len < sizeof(p->id.name) - 2);
|
||||
memcpy(p->id.name + 2, AI_DEFAULT_MATERIAL_NAME, len);
|
||||
|
||||
// Note: MSVC11 does not zero-initialize Material here, although it should.
|
||||
// Thus all relevant fields should be explicitly initialized. We cannot add
|
||||
|
||||
@@ -546,9 +546,9 @@ void NFFImporter::InternReadFile(const std::string &file, aiScene *pScene, IOSys
|
||||
// We need to add a new mesh to the list. We assign
|
||||
// an unique name to it to make sure the scene will
|
||||
// pass the validation step for the moment.
|
||||
// TODO: fix naming of objects in the scenegraph later
|
||||
// TODO: fix naming of objects in the scene-graph later
|
||||
if (objectName.length()) {
|
||||
::strcpy(mesh->name, objectName.c_str());
|
||||
::strncpy(mesh->name, objectName.c_str(), objectName.size());
|
||||
ASSIMP_itoa10(&mesh->name[objectName.length()], 30, subMeshIdx++);
|
||||
}
|
||||
|
||||
|
||||
@@ -455,11 +455,10 @@ void SMDImporter::CreateOutputNodes() {
|
||||
delete pcOldRoot;
|
||||
|
||||
pScene->mRootNode->mParent = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
::strcpy(pScene->mRootNode->mName.data, "<SMD_root>");
|
||||
} else {
|
||||
static constexpr char rootName[11] = "<SMD_root>";
|
||||
pScene->mRootNode->mName.length = 10;
|
||||
::strncpy(pScene->mRootNode->mName.data, rootName, pScene->mRootNode->mName.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -631,8 +631,9 @@ void glTFImporter::ImportEmbeddedTextures(glTF::Asset &r) {
|
||||
numEmbeddedTexs += 1;
|
||||
}
|
||||
|
||||
if (numEmbeddedTexs == 0)
|
||||
if (numEmbeddedTexs == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
mScene->mTextures = new aiTexture *[numEmbeddedTexs];
|
||||
|
||||
@@ -657,11 +658,13 @@ void glTFImporter::ImportEmbeddedTextures(glTF::Asset &r) {
|
||||
if (!img.mimeType.empty()) {
|
||||
const char *ext = strchr(img.mimeType.c_str(), '/') + 1;
|
||||
if (ext) {
|
||||
if (strcmp(ext, "jpeg") == 0) ext = "jpg";
|
||||
if (strncmp(ext, "jpeg", 4) == 0) {
|
||||
ext = "jpg";
|
||||
}
|
||||
|
||||
size_t len = strlen(ext);
|
||||
const size_t len = strlen(ext);
|
||||
if (len <= 3) {
|
||||
strcpy(tex->achFormatHint, ext);
|
||||
strncpy(tex->achFormatHint, ext, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1630,7 +1630,7 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) {
|
||||
if (!img.mimeType.empty()) {
|
||||
const char *ext = strchr(img.mimeType.c_str(), '/') + 1;
|
||||
if (ext) {
|
||||
if (strcmp(ext, "jpeg") == 0) {
|
||||
if (strncmp(ext, "jpeg", 4) == 0) {
|
||||
ext = "jpg";
|
||||
} else if (strcmp(ext, "ktx2") == 0) { // basisu: ktx remains
|
||||
ext = "kx2";
|
||||
@@ -1638,9 +1638,9 @@ void glTF2Importer::ImportEmbeddedTextures(glTF2::Asset &r) {
|
||||
ext = "bu";
|
||||
}
|
||||
|
||||
size_t len = strlen(ext);
|
||||
const size_t len = strlen(ext);
|
||||
if (len <= 3) {
|
||||
strcpy(tex->achFormatHint, ext);
|
||||
strncpy(tex->achFormatHint, ext, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user