mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-14 00:23:50 +00:00
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:
parent
e42f8f1c03
commit
01ab2a315c
1 changed files with 6 additions and 9 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue