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

Commit

Permalink
replace MSVC-only *vsnprintf_s, _snprintf
Browse files Browse the repository at this point in the history
_ultoa_s, _ltoa_s
  • Loading branch information
q4a committed Jan 11, 2022
1 parent 3fdb177 commit 5d8e8e9
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 32 deletions.
10 changes: 5 additions & 5 deletions src/apps/engine/src/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void COMPILER::Trace(const char *data_PTR, ...)
char LogBuffer[4096];
va_list args;
va_start(args, data_PTR);
_vsnprintf_s(LogBuffer, sizeof(LogBuffer) - 4, data_PTR, args);
vsnprintf(LogBuffer, sizeof(LogBuffer) - 4, data_PTR, args);
va_end(args);
logTrace_->trace(LogBuffer);
}
Expand All @@ -227,7 +227,7 @@ void COMPILER::DTrace(const char *data_PTR, ...)
char LogBuffer[4096];
va_list args;
va_start(args, data_PTR);
_vsnprintf_s(LogBuffer, sizeof(LogBuffer) - 4, data_PTR, args);
vsnprintf(LogBuffer, sizeof(LogBuffer) - 4, data_PTR, args);
va_end(args);
logTrace_->trace(LogBuffer);
}
Expand Down Expand Up @@ -300,7 +300,7 @@ void COMPILER::SetError(const char *data_PTR, ...)
char ErrorBuffer[MAX_PATH + BUFSIZ];
va_list args;
va_start(args, data_PTR);
_vsnprintf_s(LogBuffer, sizeof(LogBuffer) - 4, data_PTR, args);
vsnprintf(LogBuffer, sizeof(LogBuffer) - 4, data_PTR, args);
uint32_t bytes;
FindErrorSource();

Expand Down Expand Up @@ -337,7 +337,7 @@ void COMPILER::SetWarning(const char *data_PTR, ...)
return;
va_list args;
va_start(args, data_PTR);
_vsnprintf_s(LogBuffer, sizeof(LogBuffer) - 4, data_PTR, args);
vsnprintf(LogBuffer, sizeof(LogBuffer) - 4, data_PTR, args);
uint32_t bytes;
FindErrorSource();

Expand Down Expand Up @@ -5796,7 +5796,7 @@ void COMPILER::SaveDataDebug(char *data_PTR, ...)
}
va_list args;
va_start(args, data_PTR);
_vsnprintf_s(LogBuffer, sizeof(LogBuffer) - 4, data_PTR, args);
vsnprintf(LogBuffer, sizeof(LogBuffer) - 4, data_PTR, args);
strcat_s(LogBuffer, "\x0d\x0a");
va_end(args);
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/engine/src/core_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ void CoreImpl::Trace(const char *format, ...)

va_list args;
va_start(args, format);
_vsnprintf_s(buffer_4k, sizeof(buffer_4k) - 4, format, args);
vsnprintf(buffer_4k, sizeof(buffer_4k) - 4, format, args);
va_end(args);
spdlog::info(buffer_4k);
}
Expand Down
4 changes: 2 additions & 2 deletions src/apps/engine/src/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ bool DATA::Convert(S_TOKEN_TYPE type)
return true;
case VAR_STRING:
Data_type = type;
_ltoa_s(lValue, buffer, 10);
sprintf(buffer, "%d", lValue);
Set(buffer);
return true;
default:
Expand All @@ -1072,7 +1072,7 @@ bool DATA::Convert(S_TOKEN_TYPE type)
return true;
case VAR_STRING:
Data_type = type;
_gcvt(fValue, 10, buffer);
gcvt(fValue, 10, buffer);
Set(buffer);
return true;
default:
Expand Down
2 changes: 1 addition & 1 deletion src/apps/engine/src/internal_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1925,7 +1925,7 @@ DATA *COMPILER::BC_CallIntFunction(uint32_t func_code, DATA *&pVResult, uint32_t
pV->Get(TempFloat1);
pV2->Get(TempLong1);
pV = SStack.Push();
_gcvt(TempFloat1, TempLong1, gs);
gcvt(TempFloat1, TempLong1, gs);
pV->Set(gs);
pVResult = pV;
return pV;
Expand Down
8 changes: 4 additions & 4 deletions src/libs/common/include/attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ class ATTRIBUTES

auto SetAttributeUseDword(const char *name, uint32_t val)
{
char buffer[128];
_ultoa_s(val, buffer, 10);
std::string buffer;
buffer = std::to_string(val);
if (name)
return SetAttribute(name, buffer) != 0;
SetValue(buffer);
return SetAttribute(name, buffer.c_str()) != 0;
SetValue(buffer.c_str());
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libs/lighter/src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ void Window::DrawLRect(float x1, float y1, float x2, float y2, uint32_t bkgColor

void Window::Print(int32_t color, float xleft, float xright, float y, float scale, bool isAlign, const char *format, ...)
{
_vsnprintf_s(stringBuffer, sizeof(stringBuffer), format, ((char *)&format + sizeof(char *)));
vsnprintf(stringBuffer, sizeof(stringBuffer), format, ((char *)&format + sizeof(char *)));
auto x = xleft;
if (isAlign)
{
Expand Down
2 changes: 1 addition & 1 deletion src/libs/location/src/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ void Location::Print(const CVECTOR &pos3D, float rad, int32_t line, float alpha,
static char buf[256];
scale *= 2.0f;
// print to the buffer
int32_t len = _vsnprintf_s(buf, sizeof(buf) - 1, format, (char *)(&format + 1));
int32_t len = vsnprintf(buf, sizeof(buf) - 1, format, (char *)(&format + 1));
buf[sizeof(buf) - 1] = 0;
// Find a position of a point on the screen
static CMatrix mtx, view, prj;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/renderer/src/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ int32_t FONT::Printf(int32_t x, int32_t y, char *data_PTR, ...)
{
va_list args;
va_start(args, data_PTR);
_vsnprintf_s(Buffer1024, sizeof(Buffer1024), data_PTR, args);
vsnprintf(Buffer1024, sizeof(Buffer1024), data_PTR, args);
va_end(args);
return Print(x, y, Buffer1024);
}
Expand Down
6 changes: 3 additions & 3 deletions src/libs/renderer/src/s_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2833,7 +2833,7 @@ int32_t DX9RENDER::Print(int32_t x, int32_t y, const char *format, ...)

va_list args;
va_start(args, format);
vsnprintf_s(Buff_4k, sizeof(Buff_4k), format, args);
vsnprintf(Buff_4k, sizeof(Buff_4k), format, args);
va_end(args);

return FontList[idFontCurrent].font->Print(x, y, Buff_4k);
Expand All @@ -2850,7 +2850,7 @@ int32_t DX9RENDER::Print(int32_t nFontNum, uint32_t color, int32_t x, int32_t y,

va_list args;
va_start(args, format);
vsnprintf_s(Buff_4k, sizeof(Buff_4k), format, args);
vsnprintf(Buff_4k, sizeof(Buff_4k), format, args);
va_end(args);

FontList[nFontNum].font->StoreFontParameters();
Expand Down Expand Up @@ -2912,7 +2912,7 @@ int32_t DX9RENDER::ExtPrint(int32_t nFontNum, uint32_t foreColor, uint32_t backC

va_list args;
va_start(args, format);
vsnprintf_s(Buff_4k, sizeof(Buff_4k), format, args);
vsnprintf(Buff_4k, sizeof(Buff_4k), format, args);
va_end(args);

pFont->StoreFontParameters();
Expand Down
2 changes: 1 addition & 1 deletion src/libs/rigging/src/sail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2045,7 +2045,7 @@ void sailPrint(VDX9RENDER *rs, const CVECTOR &pos3D, float rad, int32_t line, co
{
static char buf[256];
// print to the buffer
int32_t len = _vsnprintf_s(buf, sizeof(buf) - 1, format, (char *)(&format + 1));
int32_t len = vsnprintf(buf, sizeof(buf) - 1, format, (char *)(&format + 1));
buf[sizeof(buf) - 1] = 0;
// Looking for a point position on the screen
static CMatrix mtx, view, prj;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/sea_ai/src/ai_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ void AIHelper::Print(float x, float y, float fScale, const char *pFormat, ...)

va_list args;
va_start(args, pFormat);
_vsnprintf_s(cBuffer, sizeof(cBuffer), pFormat, args);
vsnprintf(cBuffer, sizeof(cBuffer), pFormat, args);
va_end(args);

pRS->ExtPrint(FONT_DEFAULT, 0xFFFFFFFF, 0x00000000, PR_ALIGN_CENTER, false, fScale, 0, 0, static_cast<int32_t>(x),
Expand Down Expand Up @@ -197,7 +197,7 @@ void AIHelper::Print3D(CVECTOR vPos, float dy, float fScale, const char *pFormat

va_list args;
va_start(args, pFormat);
_vsnprintf_s(Buff_4k, sizeof(Buff_4k), pFormat, args);
vsnprintf(Buff_4k, sizeof(Buff_4k), pFormat, args);
va_end(args);

pRS->ExtPrint(FONT_DEFAULT, 0xFFFFFFFF, 0x00000000, PR_ALIGN_CENTER, false, fScale, 0, 0, static_cast<int32_t>(vPos.x),
Expand Down
2 changes: 1 addition & 1 deletion src/libs/sound_service/src/sound_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ void SoundService::DebugPrint3D(const CVECTOR &pos3D, float rad, int32_t line, f
{
static char buf[256];
// print to the buffer
int32_t len = _vsnprintf_s(buf, sizeof(buf) - 1, format, (char *)(&format + 1));
int32_t len = vsnprintf(buf, sizeof(buf) - 1, format, (char *)(&format + 1));
buf[sizeof(buf) - 1] = 0;
// Looking for a point position on the screen
static CMatrix mtx, view, prj;
Expand Down
8 changes: 4 additions & 4 deletions src/libs/steam_api/src/achievements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,10 @@ void CSteamStatsAchievements::OnUserStatsReceived(UserStatsReceived_t *pCallback
Achievement_t &ach = g_Achievements[iAch];

SteamUserStats()->GetAchievement(ach.m_pchAchievementID, &ach.m_bAchieved);
_snprintf(ach.m_rgchName, sizeof(ach.m_rgchName), "%s",
snprintf(ach.m_rgchName, sizeof(ach.m_rgchName), "%s",
SteamUserStats()->GetAchievementDisplayAttribute(ach.m_pchAchievementID, "name"));

_snprintf(ach.m_rgchDescription, sizeof(ach.m_rgchDescription), "%s",
snprintf(ach.m_rgchDescription, sizeof(ach.m_rgchDescription), "%s",
SteamUserStats()->GetAchievementDisplayAttribute(ach.m_pchAchievementID, "desc"));

Stat_t &stat = g_Stats[iAch];
Expand Down Expand Up @@ -389,13 +389,13 @@ void CSteamStatsAchievements::OnAchievementStored(UserAchievementStored_t *pCall
if (pCallback->m_nMaxProgress == 0)
{
// char buffer[128];
// _snprintf( buffer, 128, "Achievement '%s' unlocked!", pCallback->m_rgchAchievementName );
// snprintf( buffer, 128, "Achievement '%s' unlocked!", pCallback->m_rgchAchievementName );
// trace( buffer );
}
else
{
// char buffer[128];
// _snprintf( buffer, 128, "Achievement '%s' progress callback, (%d,%d)\n",
// snprintf( buffer, 128, "Achievement '%s' progress callback, (%d,%d)\n",
// pCallback->m_rgchAchievementName, pCallback->m_nCurProgress, pCallback->m_nMaxProgress );
// trace( buffer );
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/worldmap/src/wdm_interface_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ void WdmInterfaceObject::FillSRectColor(Vertex *vrt, uint32_t color)
// Display text in a given strip horizontally and at a given height
void WdmInterfaceObject::Print(int32_t font, int32_t color, float xleft, float xright, float y, const char *format, ...)
{
_vsnprintf_s(stringBuffer, sizeof(stringBuffer), format, ((char *)&format + sizeof(char *)));
vsnprintf(stringBuffer, sizeof(stringBuffer), format, ((char *)&format + sizeof(char *)));
const auto strw = wdmObjects->rs->StringWidth(stringBuffer, font);
const auto x = (xright + xleft - strw) * 0.5f;
wdmObjects->rs->Print(font, color, static_cast<int32_t>(x), static_cast<int32_t>(y), stringBuffer);
Expand Down
6 changes: 3 additions & 3 deletions src/libs/worldmap/src/wdm_wind_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void WdmWindUI::LRender(VDX9RENDER *rs)
// write the amount of rum
if (rum)
{
_snprintf(tbuf, sizeof(tbuf) - 1, "%i", rum.value());
snprintf(tbuf, sizeof(tbuf) - 1, "%i", rum.value());
tbuf[sizeof(tbuf) - 1] = 0;
fw = rs->StringWidth(tbuf, font, resizeRatio, static_cast<int32_t>(w));

Expand All @@ -310,15 +310,15 @@ void WdmWindUI::LRender(VDX9RENDER *rs)
DrawRects(buf, 1, "WdmDrawMapBlend");

// display a line with coordinates
_snprintf(tbuf, sizeof(tbuf) - 1, "%s", wdmObjects->coordinate.c_str());
snprintf(tbuf, sizeof(tbuf) - 1, "%s", wdmObjects->coordinate.c_str());
tbuf[sizeof(tbuf) - 1] = 0;
fw = rs->StringWidth(tbuf, font, resizeRatio, static_cast<int32_t>(w));
fh = rs->CharHeight(font);

rs->ExtPrint(font, 0xffffffff, 0x00000000, PR_ALIGN_CENTER, true, resizeRatio, 0, 0, int32_t(cx),
int32_t(cy + (64.0f + 32.0f) * resizeRatio), tbuf);

_snprintf(tbuf, sizeof(tbuf) - 1, "%s", wdmObjects->stCoordinate);
snprintf(tbuf, sizeof(tbuf) - 1, "%s", wdmObjects->stCoordinate);
tbuf[sizeof(tbuf) - 1] = 0;
fw = rs->StringWidth(tbuf, font, resizeRatio, static_cast<int32_t>(w));
fh = rs->CharHeight(font);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/xinterface/src/editor/xfont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void GIFont::Print(float x, float y, const char *pcFormat, ...) const
char param[4096];
va_list args;
va_start(args, pcFormat);
_vsnprintf_s(param, sizeof(param), pcFormat, args);
vsnprintf(param, sizeof(param), pcFormat, args);
va_end(args);
m_pEditor->m_pRS->ExtPrint(m_nFontID, m_dwColor, m_dwBackColor, PR_ALIGN_LEFT, false, m_fScale,
m_pEditor->m_pGIOwner->GetScreenWidth(), m_pEditor->m_pGIOwner->GetScreenHeight(),
Expand Down

0 comments on commit 5d8e8e9

Please sign in to comment.