Przeglądaj źródła

Corrected some GCC 7.1+ compile warnings (#3522)

* Fixes #2787 and fixes #3513.
* Resolved some format-truncation warnings.
* The remaining will be fixed at a later time.
Thanks to @RadianFord and @Lemongrass3110!
Aleos 6 lat temu
rodzic
commit
926e37cb65

+ 3 - 3
src/char/int_mail.cpp

@@ -487,7 +487,7 @@ void mapif_Mail_return(int fd, uint32 char_id, int mail_id)
 		// If it was not sent by the server, since we do not want to return mails to the server
 		else if( msg.send_id != 0 )
 		{
-			char temp_[MAIL_TITLE_LENGTH];
+			char temp_[MAIL_TITLE_LENGTH + 3];
 
 			// swap sender and receiver
 			SWAP(msg.send_id, msg.dest_id);
@@ -496,8 +496,8 @@ void mapif_Mail_return(int fd, uint32 char_id, int mail_id)
 			safestrncpy(msg.dest_name, temp_, NAME_LENGTH);
 
 			// set reply message title
-			snprintf(temp_, MAIL_TITLE_LENGTH, "RE:%s", msg.title);
-			safestrncpy(msg.title, temp_, MAIL_TITLE_LENGTH);
+			snprintf(temp_, sizeof(temp_), "RE:%s", msg.title);
+			safestrncpy(msg.title, temp_, sizeof(temp_));
 
 			msg.status = MAIL_NEW;
 			msg.type = MAIL_INBOX_RETURNED;

+ 2 - 2
src/common/grfio.cpp

@@ -632,8 +632,8 @@ static int grfio_entryread(const char* grfname, int gentry)
 static bool grfio_parse_restable_row(const char* row)
 {
 	char w1[256], w2[256];
-	char src[256], dst[256];
-	char local[256];
+	char src[512], dst[512];
+	char local[512];
 	FILELIST* entry;
 
 	if( sscanf(row, "%255[^#\r\n]#%255[^#\r\n]#", w1, w2) != 2 )

+ 1 - 1
src/common/utils.cpp

@@ -216,7 +216,7 @@ void findfile(const char *p, const char *pat, void (func)(const char*))
 	DIR* dir;					// pointer to the scanned directory.
 	struct dirent* entry;		// pointer to one directory entry.
 	struct stat dir_stat;       // used by stat().
-	char tmppath[MAX_DIR_PATH+1];
+	char tmppath[MAX_DIR_PATH * 2];
 	char path[MAX_DIR_PATH+1]= ".";
 	const char *pattern = (pat==NULL)? "" : pat;
 	if(p!=NULL) strcpy(path,p);

+ 6 - 6
src/map/atcommand.cpp

@@ -6609,7 +6609,7 @@ ACMD_FUNC(cleanarea)
  *------------------------------------------*/
 ACMD_FUNC(npctalk)
 {
-	char name[NPC_NAME_LENGTH],mes[100],temp[100];
+	char name[NPC_NAME_LENGTH],mes[100],temp[CHAT_SIZE_MAX];
 	struct npc_data *nd;
 	bool ifcolor=(*(command + 8) != 'c' && *(command + 8) != 'C')?0:1;
 	unsigned long color=0;
@@ -6646,7 +6646,7 @@ ACMD_FUNC(npctalk)
 
 ACMD_FUNC(pettalk)
 {
-	char mes[100],temp[100];
+	char mes[100],temp[CHAT_SIZE_MAX];
 	struct pet_data *pd;
 
 	nullpo_retr(-1, sd);
@@ -7537,7 +7537,7 @@ ACMD_FUNC(homhungry)
  *------------------------------------------*/
 ACMD_FUNC(homtalk)
 {
-	char mes[100],temp[100];
+	char mes[100],temp[CHAT_SIZE_MAX];
 
 	nullpo_retr(-1, sd);
 
@@ -8128,7 +8128,7 @@ ACMD_FUNC(fakename)
  * Ragnarok Resources
  *------------------------------------------*/
 ACMD_FUNC(mapflag) {
-	char flag_name[CHAT_SIZE_MAX];
+	char flag_name[50];
 	short flag = 0, i, j;
 	std::string buf;
 
@@ -8136,7 +8136,7 @@ ACMD_FUNC(mapflag) {
 
 	memset(flag_name, '\0', sizeof(flag_name));
 
-	if (!message || !*message || (sscanf(message, "%99s %6hd", flag_name, &flag) < 1)) {
+	if (!message || !*message || (sscanf(message, "%49s %6hd", flag_name, &flag) < 1)) {
 		clif_displaymessage(sd->fd,msg_txt(sd,1311)); // Enabled Mapflags in this map:
 		clif_displaymessage(sd->fd,"----------------------------------");
 		for( i = MF_MIN; i < MF_MAX; i++ ){
@@ -10424,7 +10424,7 @@ bool is_atcommand(const int fd, struct map_session_data* sd, const char* message
 	char output[CHAT_SIZE_MAX];
 
 	//Reconstructed message
-	char atcmd_msg[CHAT_SIZE_MAX];
+	char atcmd_msg[CHAT_SIZE_MAX * 2];
 
 	TBL_PC * ssd = NULL; //sd for target
 	AtCommandInfo * info;

+ 8 - 7
src/map/mob.cpp

@@ -3739,13 +3739,14 @@ int mobskill_use(struct mob_data *md, unsigned int tick, int event)
 			struct mob_chat *mc = mob_chat(ms[i].msg_id);
 
 			if (mc) {
-				char temp[CHAT_SIZE_MAX];
-				char name[NAME_LENGTH];
+				std::string name = md->name, output;
+				std::size_t unique = name.find("#");
 
-				snprintf(name, sizeof name,"%s", md->name);
-				strtok(name, "#"); // discard extra name identifier if present [Daegaladh]
-				snprintf(temp, sizeof temp,"%s : %s", name, mc->msg);
-				clif_messagecolor(&md->bl, mc->color, temp, true, AREA_CHAT_WOC);
+				if (unique != std::string::npos)
+					name = name.substr(0, unique); // discard extra name identifier if present [Daegaladh]
+				output = name + " : " + mc->msg;
+
+				clif_messagecolor(&md->bl, mc->color, output.c_str(), true, AREA_CHAT_WOC);
 			}
 		}
 		if(!(battle_config.mob_ai&0x200)) { //pass on delay to same skill.
@@ -4469,7 +4470,7 @@ static bool mob_parse_row_chatdb(char* fields[], int columns, int current)
 	}
 
 	if(len>(CHAT_SIZE_MAX-1)){
-		ShowError("mob_chat: readdb: Message too long! Line %d, id: %d\n", current, msg_id);
+		ShowError("mob_parse_row_chatdb: Message too long! Line %d, id: %d\n", current, msg_id);
 		return false;
 	}
 	else if( !len ){

+ 1 - 1
src/map/npc.cpp

@@ -3350,7 +3350,7 @@ int npc_duplicate4instance(struct npc_data *snd, int16 m) {
 			clif_spawn(&wnd->bl);
 		strdb_put(npcname_db, wnd->exname, wnd);
 	} else {
-		static char w1[50], w2[50], w3[50], w4[50];
+		static char w1[128], w2[128], w3[128], w4[128];
 		const char* stat_buf = "- call from instancing subsystem -\n";
 
 		snprintf(w1, sizeof(w1), "%s,%d,%d,%d", mapdata->name, snd->bl.x, snd->bl.y, snd->ud.dir);

+ 1 - 1
src/map/npc_chat.cpp

@@ -372,7 +372,7 @@ int npc_chat_sub(struct block_list* bl, va_list ap)
 				// save out the matched strings
 				for (i = 0; i < r; i++)
 				{
-					char var[6], val[255];
+					char var[255], val[255];
 					snprintf(var, sizeof(var), "$@p%i$", i);
 					pcre_copy_substring(msg, offsets, r, i, val, sizeof(val));
 					set_var(sd, var, val);