Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #319 from storm-devs/feature/use-std_size
Browse files Browse the repository at this point in the history
replace MSVC-only _countof with std::size
  • Loading branch information
espkk authored Jan 15, 2022
2 parents 8932f2e + f67c350 commit c1a3975
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/apps/engine/src/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7218,7 +7218,7 @@ void COMPILER::FormatDialog(char *file_name)
// fio->_WriteFile(fhH,sFileName,strlen(sFileName),&dwR);
// fio->_WriteFile(fhH,sNewLine,strlen(sNewLine),&dwR);

constexpr size_t newline_len = _countof(sNewLine) - 1;
constexpr size_t newline_len = std::size(sNewLine) - 1;
do
{
Token_type = Token.FormatGet();
Expand Down Expand Up @@ -7251,7 +7251,7 @@ void COMPILER::FormatDialog(char *file_name)
else
{
fio->_WriteFile(fileS2, Token.GetData(), strlen(Token.GetData()));
fio->_WriteFile(fileS2, ",", _countof(",") - 1);
fio->_WriteFile(fileS2, ",", std::size(",") - 1);
fio->_WriteFile(fileS2, sNewLine, newline_len);
sprintf_s(sFileName, "DLG_TEXT[%d]", nTxt);
fio->_WriteFile(fileS, sFileName, strlen(sFileName));
Expand Down Expand Up @@ -7300,7 +7300,7 @@ void COMPILER::FormatDialog(char *file_name)
}
if (Token_type != DOT)
{
constexpr size_t newline_len = _countof(sNewLine) - 1;
constexpr size_t newline_len = std::size(sNewLine) - 1;
do
{
Token_type = Token.FormatGet();
Expand Down Expand Up @@ -7333,7 +7333,7 @@ void COMPILER::FormatDialog(char *file_name)
else
{
fio->_WriteFile(fileS2, Token.GetData(), strlen(Token.GetData()));
fio->_WriteFile(fileS2, ",", _countof(",") - 1);
fio->_WriteFile(fileS2, ",", std::size(",") - 1);
fio->_WriteFile(fileS2, sNewLine, newline_len);
sprintf_s(sFileName, "DLG_TEXT[%d]", nTxt);
fio->_WriteFile(fileS, sFileName, strlen(sFileName));
Expand Down
4 changes: 2 additions & 2 deletions src/libs/diagnostics/src/seh_extractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ void seh_extractor::sink(const sink_func f, EXCEPTION_RECORD *next) const
// sink error code message
if (record->ExceptionCode) {
const auto error_message = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_HMODULE,
LoadLibrary(L"ntdll"), code_, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, _countof(buf), nullptr);
LoadLibrary(L"ntdll"), code_, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, std::size(buf), nullptr);
if (error_message > 0) {
f(buf);
}
}

// sink exc magic
const auto [_,size] = std::format_to_n(buf, _countof(buf), "magic={:#x} (classified {})", magic, check_magic(magic));
const auto [_,size] = std::format_to_n(buf, std::size(buf), "magic={:#x} (classified {})", magic, check_magic(magic));
buf[size] = '\0';
f(buf);

Expand Down
2 changes: 1 addition & 1 deletion src/libs/location/src/fader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ bool Fader::Init()
drawbuf_base[5].u = 1.0f;
drawbuf_base[5].v = 1.0f;

for (size_t i = 0; i < _countof(drawbuf_base); ++i )
for (size_t i = 0; i < std::size(drawbuf_base); ++i)
{
drawbuf_back[i] = {drawbuf_base[i].x, drawbuf_base[i].y, drawbuf_base[i].z, drawbuf_base[i].rhw, {},
drawbuf_base[i].u, drawbuf_base[i].v};
Expand Down
2 changes: 1 addition & 1 deletion src/libs/particles/src/manager/particle_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool ParticleManager::OpenProject(const char *FileName)
for (auto n = 0; n < 9999; n++)
{
char buf[64];
snprintf(buf, _countof(buf), "System_%04d", n);
snprintf(buf, std::size(buf), "System_%04d", n);
// Section.Format("System_%04d", n);
const auto ReadSuccess = IniFile->ReadString("Manager", buf, IniStringBuffer, 8192, "none");
if (!ReadSuccess)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/renderer/src/s_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ int32_t DX9RENDER::TextureCreate(const char *fname)
strcpy_s(_fname, fname);
}

if (strlen(_fname) > _countof(".tx") - 1)
if (strlen(_fname) > std::size(".tx") - 1)
{
if (storm::iEquals(&_fname[strlen(_fname) - 3], ".tx"))
_fname[strlen(_fname) - 3] = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/ship/src/ship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ void SHIP::MastFall(mast_t *pM)
int32_t iNum, iBase;
char cMastNodeName[256];
sprintf_s(cMastNodeName, "%s", pM->pNode->GetName());
sscanf((char *)&cMastNodeName[_countof(MAST_IDENTIFY) - 1], "%d", &iNum);
sscanf((char *)&cMastNodeName[std::size(MAST_IDENTIFY) - 1], "%d", &iNum);
iBase = iNum / TOPMAST_BEGIN;
// core.Trace("SHIP::MastFall : nodeName %s iNum = %d base = %d iNumMasts = %d", cMastNodeName, iNum,
// iBase, iNumMasts );
Expand All @@ -955,7 +955,7 @@ void SHIP::MastFall(mast_t *pM)
if (pMast && pMast->pNode && !pMasts[i].bBroken)
{
sprintf_s(str, "%s", pMast->pNode->GetName());
sscanf((char *)&str[_countof(MAST_IDENTIFY) - 1], "%d", &iMastNum);
sscanf((char *)&str[std::size(MAST_IDENTIFY) - 1], "%d", &iMastNum);
bool bOk = false;
if (iNum < TOPMAST_BEGIN) // mast, bring down all the topmills
{
Expand Down
8 changes: 4 additions & 4 deletions src/libs/ship/src/ship_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ bool SHIP::BuildMasts()
}
const auto *const cNodeName = pNode->GetName();

if (_strnicmp(cNodeName, MAST_IDENTIFY, _countof(MAST_IDENTIFY) - 1) == 0)
if (_strnicmp(cNodeName, MAST_IDENTIFY, std::size(MAST_IDENTIFY) - 1) == 0)
{
CVECTOR vBSize, vBCenter, vUp, vDown, vTemp;

auto *pAMasts = GetACharacter()->FindAClass(GetACharacter(), "Ship.Masts");
if (!pAMasts)
pAMasts = GetACharacter()->CreateSubAClass(GetACharacter(), "Ship.Masts");

sscanf(static_cast<const char *>(&cNodeName[_countof(MAST_IDENTIFY) - 1]), "%d", &iNum);
sscanf(static_cast<const char *>(&cNodeName[std::size(MAST_IDENTIFY) - 1]), "%d", &iNum);
pMasts.resize(iNumMasts + 1);

auto *pM = &pMasts[iNumMasts];
Expand Down Expand Up @@ -245,15 +245,15 @@ bool SHIP::BuildHulls()
if (!pNode)
break;
const auto *const cNodeName = pNode->GetName();
if (_strnicmp(cNodeName, HULL_IDENTIFY, _countof(HULL_IDENTIFY) - 1) == 0)
if (_strnicmp(cNodeName, HULL_IDENTIFY, std::size(HULL_IDENTIFY) - 1) == 0)
{
CVECTOR vBSize, vBCenter, vUp, vDown, vTemp;

auto *pAHulls = GetACharacter()->FindAClass(GetACharacter(), "Ship.Hulls");
if (!pAHulls)
pAHulls = GetACharacter()->CreateSubAClass(GetACharacter(), "Ship.Hulls");

sscanf((const char *)&cNodeName[_countof(HULL_IDENTIFY) - 1], "%d", &iNum);
sscanf((const char *)&cNodeName[std::size(HULL_IDENTIFY) - 1], "%d", &iNum);
pHulls.resize(iNumHulls + 1);

hull_t *pM = &pHulls[iNumHulls];
Expand Down
2 changes: 1 addition & 1 deletion src/libs/tornado/src/debris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void Debris::Draw(VDX9RENDER *rs)

void Debris::AddModel(const char *modelName, float prt, float spd)
{
if (numModels > _countof(mdl))
if (numModels > std::size(mdl))
return;
// Create a model
entid_t id;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/xinterface/src/xinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3139,7 +3139,7 @@ char *AddAttributesStringsToBuffer(char *inBuffer, char *prevStr, ATTRIBUTES *pA
{
size_t prevLen = 0;
if (prevStr != nullptr)
prevLen = strlen(prevStr) + _countof(".") - 1;
prevLen = strlen(prevStr) + std::size(".") - 1;

const int q = pAttr->GetAttributesNum();
for (int k = 0; k < q; k++)
Expand All @@ -3152,7 +3152,7 @@ char *AddAttributesStringsToBuffer(char *inBuffer, char *prevStr, ATTRIBUTES *pA
const char *attrName = pA->GetThisName();
if (attrName && attrVal && attrVal[0])
{
int nadd = _countof("\n") - 1 + strlen(attrName) + _countof("=") - 1 + strlen(attrVal) + 1;
int nadd = std::size("\n") - 1 + strlen(attrName) + std::size("=") - 1 + strlen(attrVal) + 1;
nadd += prevLen;
if (inBuffer != nullptr)
nadd += strlen(inBuffer);
Expand Down

0 comments on commit c1a3975

Please sign in to comment.