From a3e458c6c5d1fc7cda0afcab74ff95f7a63b728a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 18 Aug 2017 20:12:08 +0300 Subject: Add missing type casts. --- src/actions/actions.cpp | 2 +- src/net/eathena/mail2handler.cpp | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/actions/actions.cpp b/src/actions/actions.cpp index 6c1025650..a8ad2a63f 100644 --- a/src/actions/actions.cpp +++ b/src/actions/actions.cpp @@ -1658,7 +1658,7 @@ impHandler(useItemInv) { Item *const item = getItemByInvIndex(param1, InventoryType::Inventory); - PlayerInfo::useEquipItem(item, param2, Sfx_true); + PlayerInfo::useEquipItem(item, CAST_S16(param2), Sfx_true); } else { diff --git a/src/net/eathena/mail2handler.cpp b/src/net/eathena/mail2handler.cpp index c52a7b5f7..3c412fc4e 100644 --- a/src/net/eathena/mail2handler.cpp +++ b/src/net/eathena/mail2handler.cpp @@ -27,6 +27,8 @@ #include "net/eathena/messageout.h" #include "net/eathena/protocolout.h" +#include "utils/checkutils.h" + #include "resources/item/item.h" #include "debug.h" @@ -106,14 +108,19 @@ void Mail2Handler::sendMail(const std::string &to, return; const std::string from = localPlayer->getName(); - const int titleSz = title.size(); - const int bodySz = body.size(); - int16_t sz = 2 + 2 + 24 + 24 + 8 + 2 + 2 + titleSz + bodySz; + const int titleSz = CAST_S32(title.size()); + const int bodySz = CAST_S32(body.size()); + int32_t sz = 2 + 2 + 24 + 24 + 8 + 2 + 2 + titleSz + bodySz; + if (sz > INT16_MAX - 4) + { + reportAlways("Mail message too big"); + return; + } if (packetVersion >= 20160600) sz += 4; createOutPacket(CMSG_MAIL2_SEND_MAIL); - outMsg.writeInt16(sz, "len"); + outMsg.writeInt16(CAST_S16(sz), "len"); outMsg.writeString(to, 24, "to"); outMsg.writeString(from, 24, "from"); outMsg.writeInt64(money, "money"); -- cgit v1.2.3-60-g2f50