From 37b1dcf5319e5de89edd41c083a27ef63ebce9da Mon Sep 17 00:00:00 2001
From: Haru <haru@dotalux.com>
Date: Fri, 11 Aug 2017 02:23:57 +0200
Subject: Fix various issues detected by coverity in rodex-related code

Follow-up to 544da439e81ff78ec102b754e16b6cc0a28a6d0a

Signed-off-by: Haru <haru@dotalux.com>
---
 src/map/clif.c  |  2 +-
 src/map/intif.c |  2 +-
 src/map/rodex.c | 10 +++++-----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/map/clif.c b/src/map/clif.c
index c13a3ea80..bd815e055 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -19249,7 +19249,7 @@ void clif_rodex_open_write_mail(int fd, const char *receiver_name, int8 result)
 	WFIFOHEAD(fd, sizeof(*sPacket));
 	sPacket = WFIFOP(fd, 0);
 	sPacket->PacketType = rodexopenwrite;
-	strncpy(sPacket->receiveName, receiver_name, NAME_LENGTH);
+	safestrncpy(sPacket->receiveName, receiver_name, NAME_LENGTH);
 	sPacket->result = result;
 	WFIFOSET(fd, sizeof(*sPacket));
 #endif
diff --git a/src/map/intif.c b/src/map/intif.c
index de862b4dd..d4fa026a2 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -2607,7 +2607,7 @@ void intif_parse_RodexCheckName(int fd)
 	}
 
 	sd->rodex.tmp.receiver_id = target_char_id;
-	strncpy(sd->rodex.tmp.receiver_name, name, NAME_LENGTH);
+	safestrncpy(sd->rodex.tmp.receiver_name, name, NAME_LENGTH);
 
 	clif->rodex_checkname_result(sd, target_char_id, target_class, target_level, name);
 }
diff --git a/src/map/rodex.c b/src/map/rodex.c
index 03191ab22..507cbf2ca 100644
--- a/src/map/rodex.c
+++ b/src/map/rodex.c
@@ -304,9 +304,9 @@ int rodex_send_mail(struct map_session_data *sd, const char *receiver_name, cons
 	if (sd->rodex.tmp.zeny > 0)
 		sd->rodex.tmp.type |= MAIL_TYPE_ZENY;
 	sd->rodex.tmp.sender_id = sd->status.char_id;
-	strncpy(sd->rodex.tmp.sender_name, sd->status.name, NAME_LENGTH);
-	strncpy(sd->rodex.tmp.title, title, RODEX_TITLE_LENGTH);
-	strncpy(sd->rodex.tmp.body, body, RODEX_BODY_LENGTH);
+	safestrncpy(sd->rodex.tmp.sender_name, sd->status.name, NAME_LENGTH);
+	safestrncpy(sd->rodex.tmp.title, title, RODEX_TITLE_LENGTH);
+	safestrncpy(sd->rodex.tmp.body, body, RODEX_BODY_LENGTH);
 
 	intif->rodex_sendmail(&sd->rodex.tmp);
 	return RODEX_SEND_MAIL_SUCCESS; // this will not inform client of the success yet. (see rodex_send_mail_result)
@@ -470,8 +470,8 @@ void rodex_get_items(struct map_session_data *sd, int8 opentype, int64 mail_id)
 			if (j < msg->items_count) {
 				struct item_data *idata = itemdb->search(sd->status.inventory[i].nameid);
 
-				if ((idata->stack.inventory && sd->status.inventory[i].amount + msg->items[i].item.amount > idata->stack.amount) ||
-					sd->status.inventory[i].amount + msg->items[i].item.amount > MAX_AMOUNT) {
+				if ((idata->stack.inventory && sd->status.inventory[i].amount + msg->items[j].item.amount > idata->stack.amount) ||
+					sd->status.inventory[i].amount + msg->items[j].item.amount > MAX_AMOUNT) {
 					clif->rodex_request_items(sd, opentype, mail_id, RODEX_GET_ITEM_FULL_ERROR);
 					return;
 				}
-- 
cgit v1.2.3-70-g09d2