Skip to content

Commit 2625a3b

Browse files
Replace shared_str::printf with standardized xr_sprintf (#1948) (#2022)
1 parent a2de142 commit 2625a3b

File tree

8 files changed

+38
-34
lines changed

8 files changed

+38
-34
lines changed

src/Layers/xrRender/ETextureParams.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,14 @@ void STextureParams::FillProp(LPCSTR base_name, PropItemVec& items, PropValue::T
161161
OnTypeChangeEvent = on_type_change;
162162
PropValue* P = PHelper().CreateToken32(items, "Type", (u32*)&type, ttype_token);
163163
P->OnChangeEvent.bind(this, &STextureParams::OnTypeChange);
164-
PHelper().CreateCaption(items, "Source" DELIMITER "Width", shared_str().printf("%d", width));
165-
PHelper().CreateCaption(items, "Source" DELIMITER "Height", shared_str().printf("%d", height));
164+
165+
shared_str temp_str;
166+
xr_sprintf(temp_str, "%d", width);
167+
PHelper().CreateCaption(items, "Source" DELIMITER "Width", temp_str);
168+
169+
xr_sprintf(temp_str, "%d", height);
170+
PHelper().CreateCaption(items, "Source" DELIMITER "Height", v);
171+
166172
PHelper().CreateCaption(items, "Source" DELIMITER "Alpha", HasAlpha() ? "present" : "absent");
167173
switch (type)
168174
{

src/xrCore/xrstring.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,20 @@ class shared_str
176176

177177
[[nodiscard]]
178178
bool equal(const shared_str& rhs) const { return (p_ == rhs.p_); }
179-
180-
shared_str& __cdecl printf(const char* format, ...)
181-
{
182-
string4096 buf;
183-
va_list p;
184-
va_start(p, format);
185-
int vs_sz = vsnprintf(buf, sizeof(buf) - 1, format, p);
186-
buf[sizeof(buf) - 1] = 0;
187-
va_end(p);
188-
if (vs_sz)
189-
_set(buf);
190-
return (shared_str&)*this;
191-
}
192179
};
193180

181+
inline int __cdecl xr_sprintf(shared_str& destination, pcstr format_string, ...)
182+
{
183+
string4096 buf;
184+
va_list args;
185+
va_start(args, format_string);
186+
const int vs_sz = vsnprintf(buf, sizeof(buf) - 1, format_string, args);
187+
buf[sizeof(buf) - 1] = 0;
188+
va_end(args);
189+
if (vs_sz >= 0)
190+
destination = buf;
191+
return vs_sz;
192+
}
194193

195194
template<>
196195
struct std::hash<shared_str>

src/xrGame/game_cl_mp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,8 +1244,7 @@ void game_cl_mp::OnEventMoneyChanged(NET_Packet& P)
12441244
}
12451245
case SKT_KIR:
12461246
{
1247-
BName.printf("%d_kill_in_row", BonusKills);
1248-
1247+
xr_sprintf(BName, "%d_kill_in_row", BonusKills);
12491248
xr_sprintf(MoneyStr, sizeof(MoneyStr), "%d", BonusKills);
12501249
BMS.m_killer.m_name = MoneyStr;
12511250
BMS.m_killer.m_color = 0xffff0000;

src/xrGame/game_cl_mp_messages_menu.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void game_cl_mp::AddMessageMenu(LPCSTR menu_section, LPCSTR snd_path, LPCSTR tea
2222
for (u32 i = 0; i < 10; i++)
2323
{
2424
shared_str LineName;
25-
LineName.printf("phrase_%d", i);
25+
xr_sprintf(LineName, "phrase_%d", i);
2626
if (!pSettings->line_exist(menu_section, LineName.c_str()))
2727
break;
2828
//---------------------------------------------------------
@@ -89,7 +89,7 @@ void game_cl_mp::LoadMessagesMenu(LPCSTR menus_section)
8989
for (int i = 0; i < 10; i++)
9090
{
9191
shared_str LineName;
92-
LineName.printf("menu_%d", i);
92+
xr_sprintf(LineName, "menu_%d", i);
9393
if (!pSettings->line_exist(menus_section, LineName.c_str()))
9494
break;
9595
shared_str menu_section = pSettings->r_string(menus_section, LineName.c_str());

src/xrGame/game_sv_mp.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ void game_sv_mp::OnVoteStart(LPCSTR VoteCommand, ClientID sender)
10551055
string256 WeatherTime = "", WeatherName = "";
10561056
sscanf(CommandParams, "%255s %255s", WeatherName, WeatherTime);
10571057

1058-
m_pVoteCommand.printf("%s %s", votecommands[i].command, WeatherTime);
1058+
xr_sprintf(m_pVoteCommand, "%s %s", votecommands[i].command, WeatherTime);
10591059
xr_sprintf(resVoteCommand, "%s %s", votecommands[i].name, WeatherName);
10601060
}
10611061
else if (!xr_stricmp(votecommands[i].name, "changemap"))
@@ -1080,11 +1080,11 @@ void game_sv_mp::OnVoteStart(LPCSTR VoteCommand, ClientID sender)
10801080
IClient* tmp_client = m_server->FindClient(tmp_predicate);
10811081
if (tmp_client)
10821082
{
1083-
m_pVoteCommand.printf("sv_kick_id %u", tmp_client->ID.value());
1083+
xr_sprintf(m_pVoteCommand, "sv_kick_id %u", tmp_client->ID.value());
10841084
}
10851085
else
10861086
{
1087-
m_pVoteCommand.printf("%s %s", votecommands[i].command, CommandParams); // backward compatibility
1087+
xr_sprintf(m_pVoteCommand, "%s %s", votecommands[i].command, CommandParams); // backward compatibility
10881088
}
10891089
xr_strcpy(resVoteCommand, VoteCommand);
10901090
}
@@ -1098,7 +1098,7 @@ void game_sv_mp::OnVoteStart(LPCSTR VoteCommand, ClientID sender)
10981098
IClient* tmp_client = m_server->FindClient(tmp_predicate);
10991099
if (tmp_client)
11001100
{
1101-
m_pVoteCommand.printf("sv_banplayer %u %d", tmp_client->ID.value(), ban_time);
1101+
xr_sprintf(m_pVoteCommand, "sv_banplayer %u %d", tmp_client->ID.value(), ban_time);
11021102
}
11031103
else
11041104
{
@@ -1112,13 +1112,13 @@ void game_sv_mp::OnVoteStart(LPCSTR VoteCommand, ClientID sender)
11121112
}
11131113
else
11141114
{
1115-
m_pVoteCommand.printf("%s %s", votecommands[i].command, CommandParams);
1115+
xr_sprintf(m_pVoteCommand, "%s %s", votecommands[i].command, CommandParams);
11161116
xr_strcpy(resVoteCommand, VoteCommand);
11171117
}
11181118
}
11191119
else
11201120
{
1121-
m_pVoteCommand.printf("%s", VoteCommand + 1);
1121+
xr_sprintf(m_pVoteCommand, "%s", VoteCommand + 1);
11221122
};
11231123

11241124
struct vote_status_setter

src/xrGame/ui/ServerList.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,8 @@ void CServerList::SrvInfo2LstSrvInfo(const ServerInfo* pServerInfo)
868868
m_itemInfo.info.address = address.c_str();
869869
m_itemInfo.info.map = pServerInfo->m_SessionName;
870870
m_itemInfo.info.game = GameTypeToStringEx(pServerInfo->m_GameType, true);
871-
m_itemInfo.info.players.printf("%d/%d", pServerInfo->m_ServerNumPlayers, pServerInfo->m_ServerMaxPlayers);
872-
m_itemInfo.info.ping.printf("%d", pServerInfo->m_Ping);
871+
xr_sprintf(m_itemInfo.info.players, "%d/%d", pServerInfo->m_ServerNumPlayers, pServerInfo->m_ServerMaxPlayers);
872+
xr_sprintf(m_itemInfo.info.ping, "%d", pServerInfo->m_Ping);
873873
m_itemInfo.info.version = pServerInfo->m_ServerVersion;
874874
m_itemInfo.info.icons.pass = pServerInfo->m_bPassword;
875875
m_itemInfo.info.icons.dedicated = pServerInfo->m_bDedicated;

src/xrGame/ui/UIActorMenuInventory.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ void CUIActorMenu::PropertiesBoxForAddon(PIItem item, bool& b_show)
11281128
if (item_in_slot_2 && item_in_slot_2->CanAttach(pScope))
11291129
{
11301130
shared_str str = StringTable().translate("st_attach_scope_to_pistol");
1131-
str.printf("%s %s", str.c_str(), item_in_slot_2->m_name.c_str());
1131+
xr_sprintf(str, "%s %s", str.c_str(), item_in_slot_2->m_name.c_str());
11321132
m_UIPropertiesBox->AddItem(str.c_str(), (void*)item_in_slot_2, INVENTORY_ATTACH_ADDON);
11331133
// m_UIPropertiesBox->AddItem( "st_attach_scope_to_pistol", (void*)item_in_slot_2,
11341134
// INVENTORY_ATTACH_ADDON );
@@ -1137,7 +1137,7 @@ void CUIActorMenu::PropertiesBoxForAddon(PIItem item, bool& b_show)
11371137
if (item_in_slot_3 && item_in_slot_3->CanAttach(pScope))
11381138
{
11391139
shared_str str = StringTable().translate("st_attach_scope_to_pistol");
1140-
str.printf("%s %s", str.c_str(), item_in_slot_3->m_name.c_str());
1140+
xr_sprintf(str, "%s %s", str.c_str(), item_in_slot_3->m_name.c_str());
11411141
m_UIPropertiesBox->AddItem(str.c_str(), (void*)item_in_slot_3, INVENTORY_ATTACH_ADDON);
11421142
// m_UIPropertiesBox->AddItem( "st_attach_scope_to_rifle", (void*)item_in_slot_3,
11431143
// INVENTORY_ATTACH_ADDON );
@@ -1151,7 +1151,7 @@ void CUIActorMenu::PropertiesBoxForAddon(PIItem item, bool& b_show)
11511151
if (item_in_slot_2 && item_in_slot_2->CanAttach(pSilencer))
11521152
{
11531153
shared_str str = StringTable().translate("st_attach_silencer_to_pistol");
1154-
str.printf("%s %s", str.c_str(), item_in_slot_2->m_name.c_str());
1154+
xr_sprintf(str, "%s %s", str.c_str(), item_in_slot_2->m_name.c_str());
11551155
m_UIPropertiesBox->AddItem(str.c_str(), (void*)item_in_slot_2, INVENTORY_ATTACH_ADDON);
11561156
// m_UIPropertiesBox->AddItem( "st_attach_silencer_to_pistol", (void*)item_in_slot_2,
11571157
// INVENTORY_ATTACH_ADDON );
@@ -1160,7 +1160,7 @@ void CUIActorMenu::PropertiesBoxForAddon(PIItem item, bool& b_show)
11601160
if (item_in_slot_3 && item_in_slot_3->CanAttach(pSilencer))
11611161
{
11621162
shared_str str = StringTable().translate("st_attach_silencer_to_pistol");
1163-
str.printf("%s %s", str.c_str(), item_in_slot_3->m_name.c_str());
1163+
xr_sprintf(str, "%s %s", str.c_str(), item_in_slot_3->m_name.c_str());
11641164
m_UIPropertiesBox->AddItem(str.c_str(), (void*)item_in_slot_3, INVENTORY_ATTACH_ADDON);
11651165
// m_UIPropertiesBox->AddItem( "st_attach_silencer_to_rifle", (void*)item_in_slot_3,
11661166
// INVENTORY_ATTACH_ADDON );
@@ -1174,7 +1174,7 @@ void CUIActorMenu::PropertiesBoxForAddon(PIItem item, bool& b_show)
11741174
if (item_in_slot_2 && item_in_slot_2->CanAttach(pGrenadeLauncher))
11751175
{
11761176
shared_str str = StringTable().translate("st_attach_gl_to_rifle");
1177-
str.printf("%s %s", str.c_str(), item_in_slot_2->m_name.c_str());
1177+
xr_sprintf(str, "%s %s", str.c_str(), item_in_slot_2->m_name.c_str());
11781178
m_UIPropertiesBox->AddItem(str.c_str(), (void*)item_in_slot_2, INVENTORY_ATTACH_ADDON);
11791179
// m_UIPropertiesBox->AddItem( "st_attach_gl_to_pistol", (void*)item_in_slot_2,
11801180
//INVENTORY_ATTACH_ADDON
@@ -1184,7 +1184,7 @@ void CUIActorMenu::PropertiesBoxForAddon(PIItem item, bool& b_show)
11841184
if (item_in_slot_3 && item_in_slot_3->CanAttach(pGrenadeLauncher))
11851185
{
11861186
shared_str str = StringTable().translate("st_attach_gl_to_rifle");
1187-
str.printf("%s %s", str.c_str(), item_in_slot_3->m_name.c_str());
1187+
xr_sprintf(str, "%s %s", str.c_str(), item_in_slot_3->m_name.c_str());
11881188
m_UIPropertiesBox->AddItem(str.c_str(), (void*)item_in_slot_3, INVENTORY_ATTACH_ADDON);
11891189
// m_UIPropertiesBox->AddItem( "st_attach_gl_to_rifle", (void*)item_in_slot_3,
11901190
//INVENTORY_ATTACH_ADDON

src/xrGame/ui/UIPdaWnd.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void CUIPdaWnd::Update()
259259
if (m_clock->GetParent() != this) // SOC
260260
{
261261
const auto date = GetGameDateAsString(InventoryUtilities::edpDateToDay, '/', true);
262-
time.printf("%s %s", time.c_str(), date.c_str());
262+
xr_sprintf(time, "%s %s", time.c_str(), date.c_str());
263263
}
264264
m_clock->SetText(time.c_str());
265265
}

0 commit comments

Comments
 (0)