Used sizeof for buffer sizes instead of hardcoding values

pull/4744/head
slinky55 2022-09-30 22:03:59 -04:00
parent e2e45f7a14
commit 38ccb7e6c9
6 changed files with 9 additions and 9 deletions

View File

@ -67,7 +67,7 @@ static void ReportWarning(const char *msg, ...) {
va_start(args, msg);
char szBuffer[3000];
const int iLen = vsnprintf(szBuffer, 3000, msg, args);
const int iLen = vsnprintf(szBuffer, sizeof(szBuffer), msg, args);
ai_assert(iLen > 0);
va_end(args);

View File

@ -1228,7 +1228,7 @@ void FBXExporter::WriteObjects ()
"Version", int32_t(101), outstream, binary, indent
);
char layerName[8];
snprintf(layerName, 8, "COLOR_%d", colorChannelIndex);
snprintf(layerName, sizeof(layerName), "COLOR_%d", colorChannelIndex);
FBX::Node::WritePropertyNode(
"Name", (const char*)layerName, outstream, binary, indent
);

View File

@ -99,7 +99,7 @@ MD5Parser::MD5Parser(char *_buffer, unsigned int _fileSize) : buffer(_buffer), b
// Report warning to the log stream
/*static*/ void MD5Parser::ReportWarning(const char *warn, unsigned int line) {
char szBuffer[1024];
::snprintf(szBuffer, 1024, "[MD5] Line %u: %s", line, warn);
::snprintf(szBuffer, sizeof(szBuffer), "[MD5] Line %u: %s", line, warn);
ASSIMP_LOG_WARN(szBuffer);
}

View File

@ -298,7 +298,7 @@ void MDLImporter::SizeCheck(const void *szPos, const char *szFile, unsigned int
}
char szBuffer[1024];
::snprintf(szBuffer, 1024, "Invalid MDL file. The file is too small "
::snprintf(szBuffer, sizeof(szBuffer), "Invalid MDL file. The file is too small "
"or contains invalid data (File: %s Line: %u)",
szFilePtr, iLine);

View File

@ -80,7 +80,7 @@ AI_WONT_RETURN void ValidateDSProcess::ReportError(const char *msg, ...) {
va_start(args, msg);
char szBuffer[3000];
const int iLen = vsnprintf(szBuffer, 3000, msg, args);
const int iLen = vsnprintf(szBuffer, sizeof(szBuffer), msg, args);
ai_assert(iLen > 0);
va_end(args);
@ -95,7 +95,7 @@ void ValidateDSProcess::ReportWarning(const char *msg, ...) {
va_start(args, msg);
char szBuffer[3000];
const int iLen = vsnprintf(szBuffer, 3000, msg, args);
const int iLen = vsnprintf(szBuffer, sizeof(szBuffer), msg, args);
ai_assert(iLen > 0);
va_end(args);

View File

@ -224,7 +224,7 @@ bool OpenDDLExport::writeValueType(Value::ValueType type, size_t numItems, std::
statement += "[";
char buffer[256];
::memset(buffer, '\0', 256 * sizeof(char));
snprintf(buffer, 256, "%d", static_cast<int>(numItems));
snprintf(buffer, sizeof(buffer), "%d", static_cast<int>(numItems));
statement += buffer;
statement += "]";
}
@ -255,7 +255,7 @@ bool OpenDDLExport::writeValue(Value *val, std::string &statement) {
std::stringstream stream;
char buffer[256];
::memset(buffer, '\0', 256 * sizeof(char));
snprintf(buffer, 256, "%d", val->getInt16());
snprintf(buffer, sizeof(buffer), "%d", val->getInt16());
statement += buffer;
} break;
case Value::ValueType::ddl_int32: {
@ -263,7 +263,7 @@ bool OpenDDLExport::writeValue(Value *val, std::string &statement) {
char buffer[256];
::memset(buffer, '\0', 256 * sizeof(char));
const int i = static_cast<int>(val->getInt32());
snprintf(buffer, 256, "%d", i);
snprintf(buffer, sizeof(buffer), "%d", i);
statement += buffer;
} break;
case Value::ValueType::ddl_int64: {