fix: achievement message silently truncated by char[256] snprintf

Long achievement names combined with sender name could exceed 256
bytes, silently cutting the message mid-word in chat. Replaced with
std::string concatenation which grows dynamically.
This commit is contained in:
Kelsi 2026-03-29 21:35:56 -07:00
parent e42f8f1c03
commit 01ab2a315c

View file

@ -1413,15 +1413,12 @@ void SpellHandler::handleAchievementEarned(network::Packet& packet) {
static_cast<unsigned long long>(guid));
senderName = tmp;
}
char buf[256];
if (!achName.empty()) {
std::snprintf(buf, sizeof(buf), "%s has earned the achievement: %s",
senderName.c_str(), achName.c_str());
} else {
std::snprintf(buf, sizeof(buf), "%s has earned an achievement! (ID %u)",
senderName.c_str(), achievementId);
}
owner_.addSystemChatMessage(buf);
// Use std::string instead of fixed char[256] — achievement names can be
// long and combined with senderName could exceed 256 bytes, silently truncating.
std::string msg = senderName + (!achName.empty()
? " has earned the achievement: " + achName
: " has earned an achievement! (ID " + std::to_string(achievementId) + ")");
owner_.addSystemChatMessage(msg);
}
LOG_INFO("SMSG_ACHIEVEMENT_EARNED: guid=0x", std::hex, guid, std::dec,