mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-17 17:43:52 +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));
|
static_cast<unsigned long long>(guid));
|
||||||
senderName = tmp;
|
senderName = tmp;
|
||||||
}
|
}
|
||||||
char buf[256];
|
// Use std::string instead of fixed char[256] — achievement names can be
|
||||||
if (!achName.empty()) {
|
// long and combined with senderName could exceed 256 bytes, silently truncating.
|
||||||
std::snprintf(buf, sizeof(buf), "%s has earned the achievement: %s",
|
std::string msg = senderName + (!achName.empty()
|
||||||
senderName.c_str(), achName.c_str());
|
? " has earned the achievement: " + achName
|
||||||
} else {
|
: " has earned an achievement! (ID " + std::to_string(achievementId) + ")");
|
||||||
std::snprintf(buf, sizeof(buf), "%s has earned an achievement! (ID %u)",
|
owner_.addSystemChatMessage(msg);
|
||||||
senderName.c_str(), achievementId);
|
|
||||||
}
|
|
||||||
owner_.addSystemChatMessage(buf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("SMSG_ACHIEVEMENT_EARNED: guid=0x", std::hex, guid, std::dec,
|
LOG_INFO("SMSG_ACHIEVEMENT_EARNED: guid=0x", std::hex, guid, std::dec,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue