浏览代码

Fixed some addtional cppcheck warnings
int8 is not readable with scanf though

Lemongrass3110 10 年之前
父节点
当前提交
93bd68b6fd
共有 12 个文件被更改,包括 41 次插入36 次删除
  1. 2 2
      src/char/int_guild.c
  2. 4 4
      src/map/atcommand.c
  3. 2 2
      src/map/battle.c
  4. 1 1
      src/map/channel.c
  5. 2 1
      src/map/clif.c
  6. 1 2
      src/map/map.c
  7. 11 10
      src/map/npc.c
  8. 7 0
      src/map/party.c
  9. 1 1
      src/map/pc.c
  10. 7 8
      src/map/script.c
  11. 1 1
      src/map/status.c
  12. 2 4
      src/tool/mapcache.c

+ 2 - 2
src/char/int_guild.c

@@ -1489,12 +1489,12 @@ int mapif_parse_GuildMemberInfoChange(int fd,int guild_id,uint32 account_id,uint
 		  }
 		case GMI_EXP:
 		{	// EXP
-			uint64 exp, old_exp=g->member[i].exp;
+			uint64 old_exp=g->member[i].exp;
 			g->member[i].exp=*((uint64 *)data);
 			g->member[i].modified = GS_MEMBER_MODIFIED;
 			if (g->member[i].exp > old_exp)
 			{
-				exp = g->member[i].exp - old_exp;
+				uint64 exp = g->member[i].exp - old_exp;
 
 				// Compute gained exp
 				if (charserv_config.guild_exp_rate != 100)

+ 4 - 4
src/map/atcommand.c

@@ -1814,7 +1814,6 @@ ACMD_FUNC(go)
 	int i;
 	int town;
 	char map_name[MAP_NAME_LENGTH];
-	int16 m;
 
 	const struct {
 		char map[MAP_NAME_LENGTH];
@@ -1983,7 +1982,7 @@ ACMD_FUNC(go)
 
 	if (town >= 0 && town < ARRAYLENGTH(data))
 	{
-		m = map_mapname2mapid(data[town].map);
+		int16 m = map_mapname2mapid(data[town].map);
 		if (m >= 0 && map[m].flag.nowarpto && !pc_has_permission(sd, PC_PERM_WARP_ANYWHERE)) {
 			clif_displaymessage(fd, msg_txt(sd,247));
 			return -1;
@@ -6042,7 +6041,7 @@ ACMD_FUNC(autolootitem)
  *------------------------------------------*/
 ACMD_FUNC(autoloottype)
 {
-	uint8 i = 0, action = 3; // 1=add, 2=remove, 3=help+list (default), 4=reset
+	uint8 action = 3; // 1=add, 2=remove, 3=help+list (default), 4=reset
 	enum item_types type = -1;
 	int ITEM_MAX = 1533;
 
@@ -6116,6 +6115,7 @@ ACMD_FUNC(autoloottype)
 			if (sd->state.autoloottype == 0)
 				clif_displaymessage(fd, msg_txt(sd,1489)); // Your autoloottype list is empty.
 			else {
+				uint8 i = 0;
 				clif_displaymessage(fd, msg_txt(sd,1490)); // Item types on your autoloottype list:
 				while (i < IT_MAX) {
 					if (sd->state.autoloottype&(1<<i)) {
@@ -8902,7 +8902,7 @@ ACMD_FUNC(accinfo) {
 	char type = 0; // type = 1, get only account name
 
 	if (!message || !*message || strlen(message) > NAME_LENGTH
-		|| ( sscanf(message, "%31s %c", query, &type) < 1))
+		|| ( sscanf(message, "%23s %c", query, &type) < 1))
 	{
 		clif_displaymessage(fd, msg_txt(sd,1365)); // Usage: @accinfo/@accountinfo <account_id/char name>
 		clif_displaymessage(fd, msg_txt(sd,1366)); // You may search partial name by making use of '%' in the search, ex. "@accinfo %Mario%" lists all characters whose name contains "Mario".

+ 2 - 2
src/map/battle.c

@@ -2501,7 +2501,6 @@ static int battle_get_weapon_element(struct Damage wd, struct block_list *src, s
 	struct map_session_data *sd = BL_CAST(BL_PC, src);
 	struct status_change *sc = status_get_sc(src);
 	struct status_data *sstatus = status_get_status_data(src);
-	uint8 i;
 	int element = skill_get_ele(skill_id, skill_lv);
 
 	//Take weapon's element
@@ -2514,6 +2513,7 @@ static int battle_get_weapon_element(struct Damage wd, struct block_list *src, s
 			element = sd->bonus.arrow_ele;
 		// on official endows override all other elements [helvetica]
 		if (sd) { //Summoning 10 talisman will endow your weapon.
+			uint8 i;
 			ARR_FIND(1, 6, i, sd->talisman[i] >= 10);
 			if (i < 5)
 				element = i;
@@ -3087,7 +3087,7 @@ static struct Damage battle_calc_multi_attack(struct Damage wd, struct block_lis
 			}
 		}
 		else if( ((sd->weapontype1 == W_REVOLVER && (skill_lv = pc_checkskill(sd,GS_CHAINACTION)) > 0) //Normal Chain Action effect
-			|| (sd && sc->count && sc->data[SC_E_CHAIN] && (skill_lv = sc->data[SC_E_CHAIN]->val2) > 0)) //Chain Action of ETERNAL_CHAIN
+			|| (sd && sc && sc->count && sc->data[SC_E_CHAIN] && (skill_lv = sc->data[SC_E_CHAIN]->val2) > 0)) //Chain Action of ETERNAL_CHAIN
 			&& rnd()%100 < 5*skill_lv ) //Success rate
 		{
 			wd.div_ = skill_get_num(GS_CHAINACTION,skill_lv);

+ 1 - 1
src/map/channel.c

@@ -382,7 +382,7 @@ int channel_chk(char *chname, char *chpass, int type){
 			return -4;
 		}
 	}
-	if (type&4 && (chpass != '\0' && strlen(chpass) > CHAN_NAME_LENGTH ) ) {
+	if (type&4 && (chpass[0] != '\0' && strlen(chpass) > CHAN_NAME_LENGTH ) ) {
 		return -3;
 	}
 

+ 2 - 1
src/map/clif.c

@@ -8641,12 +8641,13 @@ void clif_messagecolor(struct block_list* bl, unsigned long color, const char* m
 
 void clif_messagecolor2(struct map_session_data *sd, unsigned long color, const char* msg)
 {
-	int fd;
 	unsigned short msg_len = strlen(msg) + 1;
 
 	nullpo_retv(sd);
 
 	if(msg_len > 0) {
+		int fd;
+
 		color = (color & 0x0000FF) << 16 | (color & 0x00FF00) | (color & 0xFF0000) >> 16; // RGB to BGR
 
 		fd = sd->fd;

+ 1 - 2
src/map/map.c

@@ -3441,7 +3441,6 @@ int parse_console(const char* buf){
 	char mapname[64];
 	int16 x = 0;
 	int16 y = 0;
-	int16 m;
 	int n;
 	struct map_session_data sd;
 
@@ -3470,7 +3469,7 @@ int parse_console(const char* buf){
 
 	if(strcmpi("admin",type) == 0 ) {
 		if(strcmpi("map",command) == 0){
-			m = map_mapname2mapid(mapname);
+			int16 m = map_mapname2mapid(mapname);
 			if( m < 0 ){
 				ShowWarning("Console: Unknown map.\n");
 				return 0;

+ 11 - 10
src/map/npc.c

@@ -2387,7 +2387,7 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
 {
 	char *p, point_str[32];
 	int m, is_discount = 0;
-	uint8 dir;
+	uint16 dir;
 	short x, y;
 	unsigned short nameid = 0;
 	struct npc_data *nd;
@@ -2401,7 +2401,7 @@ static const char* npc_parse_shop(char* w1, char* w2, char* w3, char* w4, const
 	else
 	{// w1=<map name>,<x>,<y>,<facing>
 		char mapname[32];  // TODO: Check why this does not use MAP_NAME_LENGTH_EXT
-		if( sscanf(w1, "%31[^,],%6hd,%6hd,%4d", mapname, &x, &y, &dir) != 4
+		if( sscanf(w1, "%31[^,],%6hd,%6hd,%4hd", mapname, &x, &y, &dir) != 4
 		||	strchr(w4, ',') == NULL )
 		{
 			ShowError("npc_parse_shop: Invalid shop definition in file '%s', line '%d'.\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
@@ -2687,7 +2687,7 @@ static const char* npc_skip_script(const char* start, const char* buffer, const
  * @return new index for next parsing
  */
 static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath, bool runOnInit) {
-	int8 dir = 0;
+	int16 dir = 0;
 	short m, x, y, xs = 0, ys = 0; // [Valaris] thanks to fov
 	struct script_code *script;
 	int i;
@@ -2708,7 +2708,7 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
 	{// npc in a map
 		char mapname[32]; // TODO: Check why this does not use MAP_NAME_LENGTH_EXT
 
-		if( sscanf(w1, "%31[^,],%6hd,%6hd,%4d", mapname, &x, &y, &dir) != 4 )
+		if( sscanf(w1, "%31[^,],%6hd,%6hd,%4hd", mapname, &x, &y, &dir) != 4 )
 		{
 			ShowError("npc_parse_script: Invalid placement format for a script in file '%s', line '%d'. Skipping the rest of file...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
 			return NULL;// unknown format, don't continue
@@ -2829,7 +2829,7 @@ static const char* npc_parse_script(char* w1, char* w2, char* w3, char* w4, cons
 const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const char* start, const char* buffer, const char* filepath)
 {
 	short x, y, m, xs = -1, ys = -1;
-	int8 dir;
+	int16 dir;
 	char srcname[128];
 	int i;
 	const char* end;
@@ -2866,7 +2866,7 @@ const char* npc_parse_duplicate(char* w1, char* w2, char* w3, char* w4, const ch
 	} else {
 		char mapname[32]; // TODO: Check why this does not use MAP_NAME_LENGTH_EXT
 
-		if( sscanf(w1, "%31[^,],%6hd,%6hd,%4d", mapname, &x, &y, &dir) != 4 ) { // <map name>,<x>,<y>,<facing>
+		if( sscanf(w1, "%31[^,],%6hd,%6hd,%4hd", mapname, &x, &y, &dir) != 4 ) { // <map name>,<x>,<y>,<facing>
 			ShowError("npc_parse_duplicate: Invalid placement format for duplicate in file '%s', line '%d'. Skipping line...\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
 			return end;// next line, try to continue
 		}
@@ -3318,7 +3318,7 @@ static const char* npc_parse_mob(char* w1, char* w2, char* w3, char* w4, const c
 	// w3=<mob name>{,<mob level>}
 	// w4=<mob id>,<amount>,<delay1>,<delay2>,<event>{,<mob size>,<mob ai>}
 	if( sscanf(w1, "%31[^,],%6hd,%6hd,%6hd,%6hd", mapname, &x, &y, &xs, &ys) < 3
-	||	sscanf(w3, "%23[^,],%d", mobname, &mob_lv) < 1
+	||	sscanf(w3, "%23[^,],%11d", mobname, &mob_lv) < 1
 	||	sscanf(w4, "%11d,%11d,%11u,%11u,%127[^,],%11d,%11d[^\t\r\n]", &class_, &num, &mob.delay1, &mob.delay2, mob.eventname, &size, &ai) < 2 )
 	{
 		ShowError("npc_parse_mob: Invalid mob definition in file '%s', line '%d'.\n * w1=%s\n * w2=%s\n * w3=%s\n * w4=%s\n", filepath, strline(buffer,start-buffer), w1, w2, w3, w4);
@@ -3564,7 +3564,7 @@ static const char* npc_parse_mapflag(char* w1, char* w2, char* w3, char* w4, con
 	else if (!strcmpi(w3, "pvp_nightmaredrop")) {
 		char drop_arg1[16], drop_arg2[16];
 		int drop_per = 0;
-		if (sscanf(w4, "%15[^,],%15[^,],%d", drop_arg1, drop_arg2, &drop_per) == 3) {
+		if (sscanf(w4, "%15[^,],%15[^,],%11d", drop_arg1, drop_arg2, &drop_per) == 3) {
 			int drop_id = 0, drop_type = 0;
 			if (!strcmpi(drop_arg1, "random"))
 				drop_id = -1;
@@ -3695,7 +3695,7 @@ static const char* npc_parse_mapflag(char* w1, char* w2, char* w3, char* w4, con
 	else if (!strcmpi(w3,"restricted")) {
 		if (state) {
 			map[m].flag.restricted=1;
-			sscanf(w4, "%d", &state); // TODO: Something should be done if it could not be read
+			sscanf(w4, "%11d", &state); // TODO: Something should be done if it could not be read
 			map[m].zone |= 1<<(state+1);
 		} else {
 			map[m].flag.restricted=0;
@@ -4054,7 +4054,6 @@ void npc_clear_pathlist(void) {
 //Clear then reload npcs files
 int npc_reload(void) {
 	struct npc_src_list *nsl;
-	int16 m, i;
 	int npc_new_min = npc_id;
 	struct s_mapiterator* iter;
 	struct block_list* bl;
@@ -4087,7 +4086,9 @@ int npc_reload(void) {
 
 	if(battle_config.dynamic_mobs)
 	{// dynamic check by [random]
+		int16 m;
 		for (m = 0; m < map_num; m++) {
+			int16 i;
 			for (i = 0; i < MAX_MOB_LIST_PER_MAP; i++) {
 				if (map[m].moblist[i] != NULL) {
 					aFree(map[m].moblist[i]);

+ 7 - 0
src/map/party.c

@@ -754,7 +754,14 @@ int party_changeleader(struct map_session_data *sd, struct map_session_data *tsd
 			return 0; // Shouldn't happen
 	} else {
 		ARR_FIND(0,MAX_PARTY,mi,p->party.member[mi].leader);
+
+		if (mi == MAX_PARTY)
+			return 0; // Shouldn't happen
+
 		ARR_FIND(0,MAX_PARTY,tmi,p->data[tmi].sd ==  tsd);
+
+		if (tmi == MAX_PARTY)
+			return 0; // Shouldn't happen
 	}
 
 	// Change leadership.

+ 1 - 1
src/map/pc.c

@@ -1895,7 +1895,7 @@ int pc_disguise(struct map_session_data *sd, int class_)
 			struct chat_data* cd;
 			nullpo_retr(1, sd);
 			cd = (struct chat_data*)map_id2bl(sd->chatID);
-			if( cd != NULL || (struct block_list*)sd == cd->owner )
+			if( cd != NULL || (struct block_list*)sd == cd->owner ) // TODO: one of those two checks is unnecessary
 				clif_dispchat(cd,0);
 		}
 	}

+ 7 - 8
src/map/script.c

@@ -17088,7 +17088,7 @@ BUILDIN_FUNC(waitingroom2bg)
 	}
 
 	n = cd->users;
-	for( i = 0; i < n && i < MAX_BG_MEMBERS; i++ )
+	for( i = 0; i < n && i < MAX_BG_MEMBERS; i++ ) // TODO: should this be MAX_CHAT_USERS?! otherwise cd->usersd[i] might be out of bounds
 	{
 		struct map_session_data *sd;
 		if( (sd = cd->usersd[i]) != NULL && bg_team_join(bg_id, sd) )
@@ -18270,7 +18270,6 @@ BUILDIN_FUNC(cleanmap)
 {
 	const char *mapname;
 	int16 m;
-	int16 x0 = 0, y0 = 0, x1 = 0, y1 = 0;
 
 	mapname = script_getstr(st, 2);
 	m = map_mapname2mapid(mapname);
@@ -18280,10 +18279,10 @@ BUILDIN_FUNC(cleanmap)
 	if ((script_lastdata(st) - 2) < 4) {
 		map_foreachinmap(atcommand_cleanfloor_sub, m, BL_ITEM);
 	} else {
-		x0 = script_getnum(st, 3);
-		y0 = script_getnum(st, 4);
-		x1 = script_getnum(st, 5);
-		y1 = script_getnum(st, 6);
+		int16 x0 = script_getnum(st, 3);
+		int16 y0 = script_getnum(st, 4);
+		int16 x1 = script_getnum(st, 5);
+		int16 y1 = script_getnum(st, 6);
 		if (x0 > 0 && y0 > 0 && x1 > 0 && y1 > 0) {
 			map_foreachinarea(atcommand_cleanfloor_sub, m, x0, y0, x1, y1, BL_ITEM);
 		} else {
@@ -19129,11 +19128,11 @@ BUILDIN_FUNC(mergeitem) {
 
 	if (script_hasdata(st, 2)) {
 		struct script_data *data = script_getdata(st, 2);
-		struct item_data *id;
 		get_val(st, data);
 
 		if (data_isstring(data)) {// "<item name>"
 			const char *name = conv_str(st,data);
+			struct item_data *id;
 			if (!(id = itemdb_searchname(name))) {
 				ShowError("buildin_mergeitem: Nonexistant item %s requested.\n", name);
 				script_pushint(st, count);
@@ -19143,7 +19142,7 @@ BUILDIN_FUNC(mergeitem) {
 		}
 		else if (data_isint(data)) {// <item id>
 			nameid = conv_num(st,data);
-			if (!(id = itemdb_exists(nameid))) {
+			if (!itemdb_exists(nameid)) {
 				ShowError("buildin_mergeitem: Nonexistant item %d requested.\n", nameid);
 				script_pushint(st, count);
 				return SCRIPT_CMD_FAILURE;

+ 1 - 1
src/map/status.c

@@ -12853,7 +12853,7 @@ static bool status_readdb_attrfix(const char *basedir,bool silent)
 				continue;
 
 			for (j = 0, p = line; j < ELE_ALL && p; j++) {
-				while (*p > 0 && *p == 32) //skipping newline and space (32=' ')
+				while (*p == 32) //skipping space (32=' ')
 					p++;
 				attr_fix_table[lv-1][i][j] = atoi(p);
 				if (battle_config.attr_recover == 0 && attr_fix_table[lv-1][i][j] < 0)

+ 2 - 4
src/tool/mapcache.c

@@ -58,8 +58,6 @@ int read_map(char *name, struct map_data *m)
 	unsigned char *gat, *rsw;
 	int water_height;
 	size_t xy, off, num_cells;
-	float height;
-	uint32 type;
 
 	// Open map GAT
 	sprintf(filename,"data\\%s.gat", name);
@@ -93,9 +91,9 @@ int read_map(char *name, struct map_data *m)
 	for (xy = 0; xy < num_cells; xy++)
 	{
 		// Height of the bottom-left corner
-		height = GetFloat( gat + off      );
+		float height = GetFloat( gat + off      );
 		// Type of cell
-		type   = GetULong( gat + off + 16 );
+		uint32 type   = GetULong( gat + off + 16 );
 		off += 20;
 
 		if (type == 0 && water_height != NO_WATER && height > water_height)