Skip to content

Commit 43b0852

Browse files
authored
Update ChatHelper.cpp, Replace sprintf with snprintf (liyunfan1223#1278)
Use snprintf instead of sprintf for item color formatting to prevent buffer overflows and to silence warnings in macOS versions.
1 parent 9ca326c commit 43b0852

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/ChatHelper.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ std::string const ChatHelper::FormatSpell(SpellInfo const* spellInfo)
382382
std::string const ChatHelper::FormatItem(ItemTemplate const* proto, uint32 count, uint32 total)
383383
{
384384
char color[32];
385-
sprintf(color, "%x", ItemQualityColors[proto->Quality]);
385+
snprintf(color, sizeof(color), "%x", ItemQualityColors[proto->Quality]);
386386

387387
std::string itemName;
388388
const ItemLocale* locale = sObjectMgr->GetItemLocale(proto->ItemId);
@@ -409,7 +409,7 @@ std::string const ChatHelper::FormatItem(ItemTemplate const* proto, uint32 count
409409
std::string const ChatHelper::FormatQItem(uint32 itemId)
410410
{
411411
char color[32];
412-
sprintf(color, "%x", ItemQualityColors[0]);
412+
snprintf(color, sizeof(color), "%x", ItemQualityColors[0]);
413413

414414
std::ostringstream out;
415415
out << "|c" << color << "|Hitem:" << itemId << ":0:0:0:0:0:0:0"

0 commit comments

Comments
 (0)