소스 검색

Various fixs
Fix bugreport:8418 (possible mapcrash from custom instance script)
Fix bugreport:8439 (pc_bonus_item_drop typos) thx to Baalberith
Fix some errors detected by cppcheck
upd install.sh (leftover of svn and wrong simlink)

lighta 11 년 전
부모
커밋
d6caec1c51
21개의 변경된 파일134개의 추가작업 그리고 121개의 파일을 삭제
  1. 25 7
      install.sh
  2. 3 3
      src/char/char.c
  3. 1 3
      src/char/int_guild.c
  4. 5 7
      src/common/core.c
  5. 2 2
      src/common/grfio.c
  6. 1 3
      src/common/malloc.c
  7. 2 4
      src/common/socket.c
  8. 3 3
      src/map/atcommand.c
  9. 6 9
      src/map/chrif.c
  10. 7 7
      src/map/clif.c
  11. 5 3
      src/map/homunculus.c
  12. 1 1
      src/map/log.c
  13. 2 0
      src/map/map.h
  14. 2 2
      src/map/mercenary.c
  15. 28 28
      src/map/mob.c
  16. 5 5
      src/map/pc.c
  17. 2 1
      src/map/pc.h
  18. 25 25
      src/map/skill.c
  19. 7 6
      src/map/unit.c
  20. 1 1
      src/map/vending.c
  21. 1 1
      tools/convert_sql.pl

+ 25 - 7
install.sh

@@ -2,18 +2,36 @@
 #source var/function
 . ./function.sh
 
+#read -p "WARNING: This target is experimental. Press Ctrl+C to cancel or Enter to continue." readEnterKey
+
+# NOTE: This requires GNU getopt.  On Mac OS X and FreeBSD, you have to install this
+# separately; see below.
+TEMP=`getopt -o d: -l destdir: -- "$@"`
+if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
+# Note the quotes around `$TEMP': they are essential!
+eval set -- "$TEMP"
+
+eval set -- "$TEMP"
+while [ $# -gt 0 ]
+do
+    case "$1" in
+    (-d | --destdir) PKG_PATH="$2"; shift;;
+    esac
+    shift
+done
+
+echo "destdir = $PKG_PATH "
 check_inst_right
 check_files
-read -p "WARNING: This target dis experimental. Press Ctrl+C to cancel or Enter to continue." readEnterKey
 mkdir -p $PKG_PATH/bin/
-mkdir -p $PKG_PATH/etc/$PKG/
-mkdir -p $PKG_PATH/var/$PKG/
+mkdir -p $PKG_PATH/etc/$PKG/conf
+mkdir -p $PKG_PATH/var/$PKG/log
 
 #we copy all file into opt/ dir and treat dir like normal unix arborescence
-rsync -r --exclude .svn db/ $PKG_PATH/var/$PKG/db
-rsync -r --exclude .svn log/ $PKG_PATH/var/$PKG/log
-rsync -r --exclude .svn conf/ $PKG_PATH/etc/$PKG/conf
-rsync -r --exclude .svn npc/ $PKG_PATH/npc
+cp -r db/ $PKG_PATH/var/$PKG/db
+if [ -d log ]; then cp -r log/ $PKG_PATH/var/$PKG/log; fi
+cp -r conf/ $PKG_PATH/etc/$PKG/conf
+cp -r npc/ $PKG_PATH/npc
 cp athena-start $PKG_PATH/	
 mv *-server* $PKG_PATH/bin/
 

+ 3 - 3
src/char/char.c

@@ -5350,7 +5350,7 @@ int char_lan_config_read(const char *lancfgName)
 		if ((line[0] == '/' && line[1] == '/') || line[0] == '\n' || line[1] == '\n')
 			continue;
 
-		if(sscanf(line,"%[^:]: %[^:]:%[^:]:%[^\r\n]", w1, w2, w3, w4) != 4) {
+		if(sscanf(line,"%63[^:]: %63[^:]:%63[^:]:%63[^\r\n]", w1, w2, w3, w4) != 4) {
 
 			ShowWarning("Error syntax of configuration file %s in line %d.\n", lancfgName, line_num);
 			continue;
@@ -5398,7 +5398,7 @@ void sql_config_read(const char* cfgName)
 		if(line[0] == '/' && line[1] == '/')
 			continue;
 
-		if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+		if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) != 2)
 			continue;
 
 		if(!strcmpi(w1,"char_db"))
@@ -5487,7 +5487,7 @@ int char_config_read(const char* cfgName)
 		if (line[0] == '/' && line[1] == '/')
 			continue;
 
-		if (sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2)
+		if (sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) != 2)
 			continue;
 
 		remove_control_chars(w1);

+ 1 - 3
src/char/int_guild.c

@@ -227,12 +227,10 @@ int inter_guild_tosql(struct guild *g,int flag)
 
 	if (flag&GS_MEMBER)
 	{
-		struct guild_member *m;
-
 		strcat(t_info, " members");
 		// Update only needed players
 		for(i=0;i<g->max_member;i++){
-			m = &g->member[i];
+			struct guild_member *m = &g->member[i];
 			if (!m->modified)
 				continue;
 			if(m->account_id) {

+ 5 - 7
src/common/core.c

@@ -268,7 +268,7 @@ const char *get_git_hash (void) {
 		char line[64];
 		char *rev = malloc(sizeof(char) * 50);
 
-		if( fgets(line, sizeof(line), fp) && sscanf(line, "%s", rev) )
+		if( fgets(line, sizeof(line), fp) && sscanf(line, "%40s", rev) )
 			snprintf(GitHash, sizeof(GitHash), "%s", rev);
 
 		free(rev);
@@ -370,12 +370,10 @@ int main (int argc, char **argv)
 
 	do_init(argc,argv);
 
-	{// Main runtime cycle
-		int next;
-		while (runflag != CORE_ST_STOP) {
-			next = do_timer(gettick_nocache());
-			do_sockets(next);
-		}
+	// Main runtime cycle
+	while (runflag != CORE_ST_STOP) { 
+		int next = do_timer(gettick_nocache());
+		do_sockets(next);
 	}
 
 	do_final();

+ 2 - 2
src/common/grfio.c

@@ -640,7 +640,7 @@ static bool grfio_parse_restable_row(const char* row)
 	char local[256];
 	FILELIST* entry;
 
-	if( sscanf(row, "%[^#\r\n]#%[^#\r\n]#", w1, w2) != 2 )
+	if( sscanf(row, "%255[^#\r\n]#%255[^#\r\n]#", w1, w2) != 2 )
 		return false;
 
 	if( strstr(w2, ".gat") == NULL && strstr(w2, ".rsw") == NULL )
@@ -790,7 +790,7 @@ void grfio_init(const char* fname)
 			if( line[0] == '/' && line[1] == '/' )
 				continue; // skip comments
 
-			if( sscanf(line, "%[^:]: %[^\r\n]", w1, w2) != 2 )
+			if( sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) != 2 )
 				continue; // skip unrecognized lines
 
 			// Entry table reading

+ 1 - 3
src/common/malloc.c

@@ -115,8 +115,6 @@ void aFree_(void *p, const char *file, int line, const char *func)
 	// ShowMessage("%s:%d: in func %s: aFree %p\n",file,line,func,p);
 	if (p)
 		FREE(p, file, line, func);
-
-	p = NULL;
 }
 
 
@@ -447,13 +445,13 @@ void _mfree(void *ptr, const char *file, int line, const char *func )
 /* Allocating blocks */
 static struct block* block_malloc(unsigned short hash)
 {
-	int i;
 	struct block *p;
 	if(hash_unfill[0] != NULL) {
 		/* Space for the block has already been secured */
 		p = hash_unfill[0];
 		hash_unfill[0] = hash_unfill[0]->unfill_next;
 	} else {
+		int i;
 		/* Newly allocated space for the block */
 		p = (struct block*)MALLOC(sizeof(struct block) * (BLOCK_ALLOC), __FILE__, __LINE__, __func__ );
 		if(p == NULL) {

+ 2 - 4
src/common/socket.c

@@ -1297,12 +1297,10 @@ int socket_getips(uint32* ips, int max)
 		else
 		{
 			int pos;
-			struct ifreq* ir;
-			struct sockaddr_in* a;
 			for( pos=0; pos < ic.ifc_len && num < max; )
 			{
-				ir = (struct ifreq*)(buf+pos);
-				a = (struct sockaddr_in*) &(ir->ifr_addr);
+				struct ifreq* ir = (struct ifreq*)(buf+pos);
+				struct sockaddr_in*a = (struct sockaddr_in*) &(ir->ifr_addr);
 				if( a->sin_family == AF_INET ){
 					ad = ntohl(a->sin_addr.s_addr);
 					if( ad != INADDR_LOOPBACK && ad != INADDR_ANY )

+ 3 - 3
src/map/atcommand.c

@@ -433,7 +433,7 @@ ACMD_FUNC(where)
 	nullpo_retr(-1, sd);
 	memset(atcmd_player_name, '\0', sizeof atcmd_player_name);
 
-	if (!message || !*message || sscanf(message, "%23[^\n]", atcmd_player_name) < 1) {
+	if (!message || !*message || sscanf(message, "%23s[^\n]", atcmd_player_name) < 1) {
 		clif_displaymessage(fd, msg_txt(sd,910)); // Please enter a player name (usage: @where <char name>).
 		return -1;
 	}
@@ -4373,12 +4373,12 @@ ACMD_FUNC(loadnpc)
 ACMD_FUNC(unloadnpc)
 {
 	struct npc_data *nd;
-	char NPCname[NAME_LENGTH+1];
+	char NPCname[NAME_LENGTH];
 	nullpo_retr(-1, sd);
 
 	memset(NPCname, '\0', sizeof(NPCname));
 
-	if (!message || !*message || sscanf(message, "%24[^\n]", NPCname) < 1) {
+	if (!message || !*message || sscanf(message, "%23[^\n]", NPCname) < 1) {
 		clif_displaymessage(fd, msg_txt(sd,1133)); // Please enter a NPC name (usage: @unloadnpc <NPC_name>).
 		return -1;
 	}

+ 6 - 9
src/map/chrif.c

@@ -727,9 +727,9 @@ void chrif_authfail(int fd) {/* HELLO WORLD. ip in RFIFOL 15 is not being used (
  */
 int auth_db_cleanup_sub(DBKey key, DBData *data, va_list ap) {
 	struct auth_node *node = db_data2ptr(data);
-	const char* states[] = { "Login", "Logout", "Map change" };
-
+	
 	if(DIFF_TICK(gettick(),node->node_created)>60000) {
+		const char* states[] = { "Login", "Logout", "Map change" };
 		switch (node->state) {
 			case ST_LOGOUT:
 				//Re-save attempt (->sd should never be null here).
@@ -1335,7 +1335,6 @@ int chrif_load_scdata(int fd) {
 
 #ifdef ENABLE_SC_SAVING
 	struct map_session_data *sd;
-	struct status_change_data *data;
 	int aid, cid, i, count;
 
 	aid = RFIFOL(fd,4); //Player Account ID
@@ -1356,7 +1355,7 @@ int chrif_load_scdata(int fd) {
 	count = RFIFOW(fd,12); //sc_count
 
 	for (i = 0; i < count; i++) {
-		data = (struct status_change_data*)RFIFOP(fd,14 + i*sizeof(struct status_change_data));
+		struct status_change_data *data = (struct status_change_data*)RFIFOP(fd,14 + i*sizeof(struct status_change_data));
 		status_change_start(NULL,&sd->bl, (sc_type)data->type, 10000, data->val1, data->val2, data->val3, data->val4, data->tick, 1|2|4|8);
 	}
 #endif
@@ -1367,13 +1366,11 @@ int chrif_load_scdata(int fd) {
 
 int chrif_skillcooldown_load(int fd) {
 	struct map_session_data *sd;
-	struct skill_cooldown_data *data;
 	int aid, cid, i, count;
 
 	aid = RFIFOL(fd, 4);
 	cid = RFIFOL(fd, 8);
 
-
 	sd = map_id2sd(aid);
 	if (!sd) {
 		ShowError("chrif_skillcooldown_load: Player of AID %d not found!\n", aid);
@@ -1385,7 +1382,7 @@ int chrif_skillcooldown_load(int fd) {
 	}
 	count = RFIFOW(fd, 12); //sc_count
 	for (i = 0; i < count; i++) {
-		data = (struct skill_cooldown_data*) RFIFOP(fd, 14 + i * sizeof (struct skill_cooldown_data));
+		struct skill_cooldown_data *data = (struct skill_cooldown_data*) RFIFOP(fd, 14 + i * sizeof (struct skill_cooldown_data));
 		skill_blockpc_start(sd, data->skill_id, data->tick);
 	}
 	return 0;
@@ -1565,7 +1562,7 @@ void chrif_parse_ack_vipActive(int fd) {
  *
  *------------------------------------------*/
 int chrif_parse(int fd) {
-	int packet_len, cmd;
+	int packet_len;
 
 	// only process data from the char-server
 	if ( fd != char_fd ) {
@@ -1590,7 +1587,7 @@ int chrif_parse(int fd) {
 	}
 
 	while ( RFIFOREST(fd) >= 2 ) {
-		cmd = RFIFOW(fd,0);
+		int cmd = RFIFOW(fd,0);
 		if (cmd < 0x2af8 || cmd >= 0x2af8 + ARRAYLENGTH(packet_len_table) || packet_len_table[cmd-0x2af8] == 0) {
 			int r = intif_parse(fd); // Passed on to the intif
 

+ 7 - 7
src/map/clif.c

@@ -1415,7 +1415,7 @@ void clif_hominfo(struct map_session_data *sd, struct homun_data *hd, int flag)
 	WBUFW(buf,31)=(unsigned short) (hd->homunculus.intimacy / 100) ;
 	WBUFW(buf,33)=0; // equip id
 	WBUFW(buf,35)=cap_value(status->rhw.atk2+status->batk, 0, INT16_MAX);
-	WBUFW(buf,37)=cap_value(status->matk_max, 0, INT16_MAX);
+	WBUFW(buf,37)=min(status->matk_max, INT16_MAX); //FIXME capping to INT16 here is too late
 	WBUFW(buf,39)=status->hit;
 	if (battle_config.hom_setting&0x10)
 		WBUFW(buf,41)=status->luk/3 + 1;	//crit is a +1 decimal value! Just display purpose.[Vicious]
@@ -13623,7 +13623,7 @@ void clif_blacksmith(struct map_session_data* sd)
 	WFIFOHEAD(fd,packet_len(0x219));
 	WFIFOW(fd,0) = 0x219;
 	//Packet size limits this list to 10 elements. [Skotlex]
-	for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
+	for (i = 0; i < min(10,MAX_FAME_LIST); i++) { //client is capped to 10 char
 		if (smith_fame_list[i].id > 0) {
 			if (strcmp(smith_fame_list[i].name, "-") == 0 &&
 				(name = map_charid2nick(smith_fame_list[i].id)) != NULL)
@@ -13676,7 +13676,7 @@ void clif_alchemist(struct map_session_data* sd)
 	WFIFOHEAD(fd,packet_len(0x21a));
 	WFIFOW(fd,0) = 0x21a;
 	//Packet size limits this list to 10 elements. [Skotlex]
-	for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
+	for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
 		if (chemist_fame_list[i].id > 0) {
 			if (strcmp(chemist_fame_list[i].name, "-") == 0 &&
 				(name = map_charid2nick(chemist_fame_list[i].id)) != NULL)
@@ -13729,7 +13729,7 @@ void clif_taekwon(struct map_session_data* sd)
 	WFIFOHEAD(fd,packet_len(0x226));
 	WFIFOW(fd,0) = 0x226;
 	//Packet size limits this list to 10 elements. [Skotlex]
-	for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
+	for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
 		if (taekwon_fame_list[i].id > 0) {
 			if (strcmp(taekwon_fame_list[i].name, "-") == 0 &&
 				(name = map_charid2nick(taekwon_fame_list[i].id)) != NULL)
@@ -15756,7 +15756,7 @@ void clif_instance_status(struct map_session_data *sd, const char *name, unsigne
 #if PACKETVER >= 20071128
 	unsigned char buf[71];
 
-	nullpo_retv(sd);
+	if(!sd) return; //party_getavailablesd can return NULL
 
 	WBUFW(buf,0) = 0x2cd;
 	safestrncpy( WBUFP(buf,2), name, 62 );
@@ -16914,7 +16914,7 @@ void clif_sub_ranklist(unsigned char *buf,int idx,struct map_session_data* sd, i
 
 	if(!skip){
 		//Packet size limits this list to 10 elements. [Skotlex]
-		for (i = 0; i < 10 && i < MAX_FAME_LIST; i++) {
+		for (i = 0; i < min(10,MAX_FAME_LIST); i++) {
 			if (list[i].id > 0) {
 				if (strcmp(list[i].name, "-") == 0 &&
 					(name = map_charid2nick(list[i].id)) != NULL)
@@ -17854,7 +17854,7 @@ void packetdb_readdb(void)
 			ln++;
 			if(line[0]=='/' && line[1]=='/')
 				continue;
-			if (sscanf(line,"%256[^:]: %256[^\r\n]",w1,w2) == 2)
+			if (sscanf(line,"%255[^:]: %255[^\r\n]",w1,w2) == 2)
 			{
 				if(strcmpi(w1,"packet_ver")==0) {
 					int prev_ver = packet_ver;

+ 5 - 3
src/map/homunculus.c

@@ -1282,9 +1282,7 @@ int read_homunculus_skilldb(void)
 
 void read_homunculus_expdb(void)
 {
-	FILE *fp;
-	char line[1024];
-	int i, j=0;
+	int i;
 	char *filename[]={
 		DBPATH"exp_homun.txt",
 		"import/exp_homun.txt"
@@ -1292,6 +1290,10 @@ void read_homunculus_expdb(void)
 
 	memset(hexptbl,0,sizeof(hexptbl));
 	for(i=0; i<ARRAYLENGTH(filename); i++){
+		FILE *fp;
+		char line[1024];
+		int j=0;
+		
 		sprintf(line, "%s/%s", db_path, filename[i]);
 		fp=fopen(line,"r");
 		if(fp == NULL){

+ 1 - 1
src/map/log.c

@@ -537,7 +537,7 @@ int log_config_read(const char* cfgName)
 		if( line[0] == '/' && line[1] == '/' )
 			continue;
 
-		if( sscanf(line, "%[^:]: %[^\r\n]", w1, w2) == 2 )
+		if( sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2) == 2 )
 		{
 			if( strcmpi(w1, "enable_logs") == 0 )
 				log_config.enable_logs = (e_log_pick_type)config_switch(w2);

+ 2 - 0
src/map/map.h

@@ -281,6 +281,7 @@ enum bl_type {
 enum npc_subtype { WARP, SHOP, SCRIPT, CASHSHOP, ITEMSHOP, POINTSHOP, TOMB };
 
 enum e_race {
+	RC_NONE=-1, //don't give us bonus
 	RC_FORMLESS=0,
 	RC_UNDEAD,
 	RC_BRUTE,
@@ -296,6 +297,7 @@ enum e_race {
 };
 
 enum e_classAE {
+	CLASS_NONE=-1, //don't give us bonus
 	CLASS_NORMAL = 0,
 	CLASS_BOSS,
 	CLASS_GUARDIAN,

+ 2 - 2
src/map/mercenary.c

@@ -377,8 +377,8 @@ int mercenary_killbonus(struct mercenary_data *md)
 
 int mercenary_kills(struct mercenary_data *md)
 {
-	md->mercenary.kill_count++;
-	md->mercenary.kill_count = cap_value(md->mercenary.kill_count, 0, INT_MAX);
+	if(md->mercenary.kill_count <= (INT_MAX-1)) //safe cap to INT_MAX
+		md->mercenary.kill_count++;
 
 	if( (md->mercenary.kill_count % 50) == 0 )
 	{

+ 28 - 28
src/map/mob.c

@@ -98,15 +98,13 @@ int mob_skill_id2skill_idx(int mob_id,uint16 skill_id);
 int mobdb_searchname(const char *str)
 {
 	int i;
-	struct mob_db* mob;
 	for(i=0;i<=MAX_MOB_DB;i++){
-		mob = mob_db(i);
+		struct mob_db *mob = mob_db(i);
 		if(mob == mob_dummy) //Skip dummy mobs.
 			continue;
 		if(strcmpi(mob->name,str)==0 || strcmpi(mob->jname,str)==0 || strcmpi(mob->sprite,str)==0)
 			return i;
 	}
-
 	return 0;
 }
 static int mobdb_searchname_array_sub(struct mob_db* mob, const char *str)
@@ -347,12 +345,9 @@ bool mob_ksprotected (struct block_list *src, struct block_list *target)
 	struct block_list *s_bl, *t_bl;
 	struct map_session_data
 		*sd,    // Source
-		*pl_sd, // Owner
 		*t_sd;  // Mob Target
-	struct status_change_entry *sce;
 	struct mob_data *md;
 	unsigned int tick = gettick();
-	char output[128];
 
 	if( !battle_config.ksprotection )
 		return false; // KS Protection Disabled
@@ -373,6 +368,10 @@ bool mob_ksprotected (struct block_list *src, struct block_list *target)
 	t_sd = BL_CAST(BL_PC,s_bl);
 
 	do {
+		struct status_change_entry *sce;
+		struct map_session_data *pl_sd; // Owner
+		char output[128];
+		
 		if( map[md->bl.m].flag.allowks || map_flag_ks(md->bl.m) )
 			return false; // Ignores GVG, PVP and AllowKS map flags
 
@@ -1340,7 +1339,7 @@ int mob_unlocktarget(struct mob_data *md, unsigned int tick)
 int mob_randomwalk(struct mob_data *md,unsigned int tick)
 {
 	const int retrycount=20;
-	int i,x,y,c,d;
+	int i,c,d;
 	int speed;
 
 	nullpo_ret(md);
@@ -1354,8 +1353,8 @@ int mob_randomwalk(struct mob_data *md,unsigned int tick)
 	if(d<5) d=5;
 	for(i=0;i<retrycount;i++){	// Search of a movable place
 		int r=rnd();
-		x=r%(d*2+1)-d;
-		y=r/(d*2+1)%(d*2+1)-d;
+		int x=r%(d*2+1)-d;
+		int y=r/(d*2+1)%(d*2+1)-d;
 		x+=md->bl.x;
 		y+=md->bl.y;
 
@@ -1828,10 +1827,11 @@ static struct item_drop* mob_setlootitem(struct item* item)
 static int mob_delay_item_drop(int tid, unsigned int tick, int id, intptr_t data)
 {
 	struct item_drop_list *list;
-	struct item_drop *ditem, *ditem_prev;
+	struct item_drop *ditem;
 	list=(struct item_drop_list *)data;
 	ditem = list->item;
 	while (ditem) {
+		struct item_drop *ditem_prev;
 		map_addflooritem(&ditem->item_data,ditem->item_data.amount,
 			list->m,list->x,list->y,
 			list->first_charid,list->second_charid,list->third_charid,4);
@@ -2117,7 +2117,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
 		int id,zeny;
 		unsigned int base_exp,job_exp;
 	} pt[DAMAGELOG_SIZE];
-	int i, temp, count, m = md->bl.m, pnum = 0;
+	int i, temp, count, m = md->bl.m;
 	int dmgbltypes = 0;  // bitfield of all bl types, that caused damage to the mob and are elligible for exp distribution
 	unsigned int mvp_damage, tick = gettick();
 	bool rebirth, homkillonly;
@@ -2199,6 +2199,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
 		(!map[m].flag.nobaseexp || !map[m].flag.nojobexp) //Gives Exp
 	) { //Experience calculation.
 		int bonus = 100; //Bonus on top of your share (common to all attackers).
+		int pnum = 0;
 		if (md->sc.data[SC_RICHMANKIM])
 			bonus += md->sc.data[SC_RICHMANKIM]->val2;
 		if(sd) {
@@ -2437,12 +2438,10 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
 			// process script-granted extra drop bonuses
 			int itemid = 0;
 			for (i = 0; i < ARRAYLENGTH(sd->add_drop) && (sd->add_drop[i].id || sd->add_drop[i].group); i++) {
-				if ( sd->add_drop[i].race == -md->mob_id ||
-					( (sd->add_drop[i].race > 0 || sd->add_drop[i].class_ > 0) && (
-						sd->add_drop[i].race & (1<<status->race) ||
-						sd->add_drop[i].class_ & (1<<status->class_)
-					)))
-				{
+				if ( sd->add_drop[i].race == -md->mob_id 
+					|| (sd->add_drop[i].race && (sd->add_drop[i].race)&(1<<status->race))
+					|| (sd->add_drop[i].class_ && (sd->add_drop[i].class_)&(1<<status->class_))
+				) {
 					//check if the bonus item drop rate should be multiplied with mob level/10 [Lupus]
 					if(sd->add_drop[i].rate < 0) {
 						//it's negative, then it should be multiplied. e.g. for Mimic,Myst Case Cards, etc
@@ -3382,7 +3381,7 @@ int mob_is_clone(int mob_id)
 int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, const char *event, int master_id, int mode, int flag, unsigned int duration)
 {
 	int mob_id;
-	int i,j,inf,skill_id, fd;
+	int i,j,inf, fd;
 	struct mob_data *md;
 	struct mob_skill *ms;
 	struct mob_db* db;
@@ -3434,7 +3433,7 @@ int mob_clone_spawn(struct map_session_data *sd, int16 m, int16 x, int16 y, cons
 
 	//Go Backwards to give better priority to advanced skills.
 	for (i=0,j = MAX_SKILL_TREE-1;j>=0 && i< MAX_MOBSKILL ;j--) {
-		skill_id = skill_tree[pc_class2idx(sd->status.class_)][j].id;
+		int skill_id = skill_tree[pc_class2idx(sd->status.class_)][j].id;
 		if (!skill_id || sd->status.skill[skill_id].lv < 1 ||
 			(skill_get_inf2(skill_id)&(INF2_WEDDING_SKILL|INF2_GUILD_SKILL)) ||
 			skill_get_nocast(skill_id)&16
@@ -3682,7 +3681,7 @@ static bool mob_parse_dbrow(char** str)
 {
 	struct mob_db *db, entry;
 	struct status_data *status;
-	int mob_id, i, k;
+	int mob_id, i;
 	double exp, maxhp;
 	struct mob_data data;
 
@@ -3847,7 +3846,7 @@ static bool mob_parse_dbrow(char** str)
 		int rate = 0, rate_adjust, type;
 		unsigned short ratemin, ratemax;
 		struct item_data *id;
-		k = 31 + MAX_MVP_DROP*2 + i*2;
+		int k = 31 + MAX_MVP_DROP*2 + i*2;
 		db->dropitem[i].nameid = atoi(str[k]);
 		if (!db->dropitem[i].nameid) {
 			db->dropitem[i].p = 0; //No drop.
@@ -4040,10 +4039,7 @@ static bool mob_readdb_mobavail(char* str[], int columns, int current)
  *------------------------------------------*/
 static int mob_read_randommonster(void)
 {
-	FILE *fp;
-	char line[1024];
-	char *str[10],*p;
-	int i,j, entries, k;
+	int i;
 	const char* mobfile[] = {
 		DBPATH"mob_branch.txt",
 		DBPATH"mob_poring.txt",
@@ -4061,7 +4057,11 @@ static int mob_read_randommonster(void)
 
 	for( i = 0; i < ARRAYLENGTH(mobfile); i++ )
 	{ // MobID,DummyName,Rate
-		entries=0;
+		FILE *fp;
+		char line[1024];
+		char *str[10],*p;
+		int j, entries=0, k;
+		
 		k = (i >= MAX_RANDOMMONSTER) ? i - MAX_RANDOMMONSTER : i;
 		mob_db_data[0]->summonper[k] = MOBID_PORING;	// Default fallback value, in case the database does not provide one
 		sprintf(line, "%s/%s", db_path, mobfile[i]);
@@ -4493,7 +4493,7 @@ static int mob_read_sqlskilldb(void)
  *------------------------------------------*/
 static bool mob_readdb_race2(char* fields[], int columns, int current)
 {
-	int race, mobid, i;
+	int race, i;
 
 	race = atoi(fields[0]);
 
@@ -4505,7 +4505,7 @@ static bool mob_readdb_race2(char* fields[], int columns, int current)
 
 	for(i = 1; i<columns; i++)
 	{
-		mobid = atoi(fields[i]);
+		int mobid = atoi(fields[i]);
 		if (mob_db(mobid) == mob_dummy)
 		{
 			ShowWarning("mob_readdb_race2: Unknown mob id %d for race2 %d.\n", mobid, race);

+ 5 - 5
src/map/pc.c

@@ -1915,10 +1915,10 @@ static int pc_bonus_item_drop(struct s_add_drop *drop, const short max, short id
 		if(
 			((id && drop[i].id == id) ||
 			(group && drop[i].group == group))
-			&& (race > 0 || class_ > -1)
+			&& ((race<RC_NONE && race<RC_MAX) || (class_<CLASS_NONE && class_<CLASS_MAX))
 		) {
-			drop[i].race |= race;
-			drop[i].class_ |= class_;
+			if(race<RC_NONE && race<RC_MAX) drop[i].race |= 1<<race;
+			if(class_<CLASS_NONE && class_<CLASS_MAX) drop[i].class_ |= 1<<class_;
 			if(drop[i].rate > 0 && rate > 0)
 			{	//Both are absolute rates.
 				if (drop[i].rate < rate)
@@ -1939,8 +1939,8 @@ static int pc_bonus_item_drop(struct s_add_drop *drop, const short max, short id
 	}
 	drop[i].id = id;
 	drop[i].group = group;
-	drop[i].race |= race;
-	drop[i].class_ |= class_;
+	if(race<RC_NONE && race<RC_MAX) drop[i].race |= 1<<race;
+	if(class_<CLASS_NONE && class_<CLASS_MAX) drop[i].class_ |= 1<<class_;
 	drop[i].rate = rate;
 	return 1;
 }

+ 2 - 1
src/map/pc.h

@@ -114,7 +114,8 @@ struct s_addeffectonskill {
 
 struct s_add_drop {
 	short id, group;
-	int race, rate, class_;
+	int rate;
+	int race, class_; //bitwise value of 1<<x
 };
 
 struct s_autobonus {

+ 25 - 25
src/map/skill.c

@@ -1651,9 +1651,9 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, uint
 
 		for (i = 0; i < ARRAYLENGTH(sd->autospell) && sd->autospell[i].id; i++) {
 
-			if(!(sd->autospell[i].flag&attack_type&BF_WEAPONMASK &&
-				 sd->autospell[i].flag&attack_type&BF_RANGEMASK &&
-				 sd->autospell[i].flag&attack_type&BF_SKILLMASK))
+			if(!( ((sd->autospell[i].flag)&attack_type)&BF_WEAPONMASK &&
+				  ((sd->autospell[i].flag)&attack_type)&BF_RANGEMASK &&
+				  ((sd->autospell[i].flag)&attack_type)&BF_SKILLMASK))
 				continue; // one or more trigger conditions were not fulfilled
 
 			skill = (sd->autospell[i].id > 0) ? sd->autospell[i].id : -sd->autospell[i].id;
@@ -1744,9 +1744,9 @@ int skill_additional_effect (struct block_list* src, struct block_list *bl, uint
 				continue;
 			if( sd->autobonus[i].active != INVALID_TIMER )
 				continue;
-			if(!(sd->autobonus[i].atk_type&attack_type&BF_WEAPONMASK &&
-				 sd->autobonus[i].atk_type&attack_type&BF_RANGEMASK &&
-				 sd->autobonus[i].atk_type&attack_type&BF_SKILLMASK))
+			if(!( ((sd->autobonus[i].atk_type)&attack_type)&BF_WEAPONMASK &&
+				  ((sd->autobonus[i].atk_type)&attack_type)&BF_RANGEMASK &&
+				  ((sd->autobonus[i].atk_type)&attack_type)&BF_SKILLMASK))
 				continue; // one or more trigger conditions were not fulfilled
 			pc_exeautobonus(sd,&sd->autobonus[i]);
 		}
@@ -1987,9 +1987,9 @@ int skill_counter_additional_effect (struct block_list* src, struct block_list *
 
 		for (i = 0; i < ARRAYLENGTH(dstsd->autospell2) && dstsd->autospell2[i].id; i++) {
 
-			if(!(dstsd->autospell2[i].flag&attack_type&BF_WEAPONMASK &&
-				 dstsd->autospell2[i].flag&attack_type&BF_RANGEMASK &&
-				 dstsd->autospell2[i].flag&attack_type&BF_SKILLMASK))
+			if(!( ((dstsd->autospell2[i].flag)&attack_type)&BF_WEAPONMASK &&
+				  ((dstsd->autospell2[i].flag)&attack_type)&BF_RANGEMASK &&
+				  ((dstsd->autospell2[i].flag)&attack_type)&BF_SKILLMASK))
 				continue; // one or more trigger conditions were not fulfilled
 
 			skill_id = (dstsd->autospell2[i].id > 0) ? dstsd->autospell2[i].id : -dstsd->autospell2[i].id;
@@ -2073,9 +2073,9 @@ int skill_counter_additional_effect (struct block_list* src, struct block_list *
 				continue;
 			if( dstsd->autobonus2[i].active != INVALID_TIMER )
 				continue;
-			if(!(dstsd->autobonus2[i].atk_type&attack_type&BF_WEAPONMASK &&
-				 dstsd->autobonus2[i].atk_type&attack_type&BF_RANGEMASK &&
-				 dstsd->autobonus2[i].atk_type&attack_type&BF_SKILLMASK))
+			if(!( ((dstsd->autobonus2[i].atk_type)&attack_type)&BF_WEAPONMASK &&
+				  ((dstsd->autobonus2[i].atk_type)&attack_type)&BF_RANGEMASK &&
+				  ((dstsd->autobonus2[i].atk_type)&attack_type)&BF_SKILLMASK))
 				continue; // one or more trigger conditions were not fulfilled
 			pc_exeautobonus(dstsd,&dstsd->autobonus2[i]);
 		}
@@ -2095,7 +2095,7 @@ int skill_break_equip (struct block_list *src,struct block_list *bl, unsigned sh
 	const enum sc_type scatk[4] = {SC_STRIPWEAPON, SC_STRIPARMOR, SC_STRIPSHIELD, SC_STRIPHELM};
 	const enum sc_type scdef[4] = {SC_CP_WEAPON, SC_CP_ARMOR, SC_CP_SHIELD, SC_CP_HELM};
 	struct status_change *sc = status_get_sc(bl);
-	int i,j;
+	int i;
 	TBL_PC *sd;
 	sd = BL_CAST(BL_PC, bl);
 	if (sc && !sc->count)
@@ -2143,7 +2143,7 @@ int skill_break_equip (struct block_list *src,struct block_list *bl, unsigned sh
 		return 0;
 	if (sd) {
 		for (i = 0; i < EQI_MAX; i++) {
-			j = sd->equip_index[i];
+			int j = sd->equip_index[i];
 			if (j < 0 || sd->status.inventory[j].attribute == 1 || !sd->inventory_data[j])
 				continue;
 
@@ -4094,7 +4094,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
 			// skill_area_temp[0] holds number of targets in area
 			// skill_area_temp[1] holds the id of the original target
 			// skill_area_temp[2] counts how many targets have already been processed
-			int sflag = skill_area_temp[0] & 0xFFF, heal;
+			int sflag = skill_area_temp[0] & 0xFFF;
 			if( flag&SD_LEVEL )
 				sflag |= SD_LEVEL; // -1 will be used in packets instead of the skill level
 			if( skill_area_temp[1] != bl->id && !(skill_get_inf2(skill_id)&INF2_NPC_SKILL) )
@@ -4114,7 +4114,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
 					sd->flicker = false;
 			}
 			else {
-				heal = (int)skill_attack(skill_get_type(skill_id), src, src, bl, skill_id, skill_lv, tick, sflag);
+				int heal = (int)skill_attack(skill_get_type(skill_id), src, src, bl, skill_id, skill_lv, tick, sflag);
 				if( skill_id == NPC_VAMPIRE_GIFT && heal > 0 ) {
 					clif_skill_nodamage(NULL, src, AL_HEAL, heal, 1);
 					status_heal(src,heal,0,0);
@@ -4663,7 +4663,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
 					break;
 
 				i = spell[s==1?0:rand()%s];// Random select of spell to be released.
-				if( s && sc->data[i] ){// Now extract the data from the preserved spell
+				if(sc->data[i] ){// Now extract the data from the preserved spell
 					skill_id = sc->data[i]->val1;
 					skill_lv = sc->data[i]->val2;
 					point = sc->data[i]->val3;
@@ -4702,7 +4702,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
 			}
 			else
 			{ // Summon Balls
-				int j = 0, k, skele;
+				int j = 0, k;
 				int spheres[5] = { 0, 0, 0, 0, 0 },
 					positions[5] = {-1,-1,-1,-1,-1 };
 
@@ -4733,7 +4733,7 @@ int skill_castend_damage_id (struct block_list* src, struct block_list *bl, uint
 				if( skill_lv == 1 ) j = 1; // Limit only to one ball
 				for( i = 0; i < j; i++ )
 				{
-					skele = WL_RELEASE - 5 + sc->data[spheres[i]]->val1 - WLS_FIRE; // Convert Ball Element into Skill ATK for balls
+					int skele = WL_RELEASE - 5 + sc->data[spheres[i]]->val1 - WLS_FIRE; // Convert Ball Element into Skill ATK for balls
 					// WL_SUMMON_ATK_FIRE, WL_SUMMON_ATK_WIND, WL_SUMMON_ATK_WATER, WL_SUMMON_ATK_GROUND
 					skill_addtimerskill(src,tick+status_get_adelay(src)*i,bl->id,0,0,skele,sc->data[spheres[i]]->val3,BF_MAGIC,flag|SD_LEVEL);
 					status_change_end(src, spheres[i], INVALID_TIMER); // Eliminate ball
@@ -7552,7 +7552,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 
 	case CG_TAROTCARD:
 		{
-			int eff, count = -1;
+			int count = -1;
 			if( rnd() % 100 > skill_lv * 8 || (tsc && tsc->data[SC_BASILICA]) ||
 			(dstmd && ((dstmd->guardian_data && dstmd->mob_id == MOBID_EMPERIUM) || mob_is_battleground(dstmd))) ) {
 				if( sd )
@@ -7563,7 +7563,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 			}
 			status_zap(src,0,skill_get_sp(skill_id,skill_lv)); // consume sp only if succeeded [Inkfish]
 			do {
-				eff = rnd() % 14;
+				int eff = rnd() % 14;
 				clif_specialeffect(bl, 523 + eff, AREA);
 				switch (eff)
 				{
@@ -9653,11 +9653,11 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 	case MH_SILENT_BREEZE: {
 			 struct status_change *ssc = status_get_sc(src);
 			 struct block_list *m_bl = battle_get_master(src);
-			 const enum sc_type scs[] = {
-				 SC_MANDRAGORA, SC_HARMONIZE, SC_DEEPSLEEP, SC_VOICEOFSIREN, SC_SLEEP, SC_CONFUSION, SC_HALLUCINATION
-			 };
 			 int heal;
 			 if(tsc){
+				 const enum sc_type scs[] = {
+				 SC_MANDRAGORA, SC_HARMONIZE, SC_DEEPSLEEP, SC_VOICEOFSIREN, SC_SLEEP, SC_CONFUSION, SC_HALLUCINATION
+				};
 				 for (i = 0; i < ARRAYLENGTH(scs); i++) {
 					 if (tsc->data[scs[i]]) status_change_end(bl, scs[i], INVALID_TIMER);
 				 }
@@ -10205,7 +10205,6 @@ int skill_castend_id(int tid, unsigned int tick, int id, intptr_t data)
 int skill_castend_pos(int tid, unsigned int tick, int id, intptr_t data)
 {
 	struct block_list* src = map_id2bl(id);
-	int maxcount;
 	struct map_session_data *sd;
 	struct unit_data *ud = unit_bl2ud(src);
 	struct mob_data *md;
@@ -10235,6 +10234,7 @@ int skill_castend_pos(int tid, unsigned int tick, int id, intptr_t data)
 	ud->skilltimer = INVALID_TIMER;
 
 	do {
+		int maxcount=0;
 		if( status_isdead(src) )
 			break;
 

+ 7 - 6
src/map/unit.c

@@ -1769,12 +1769,12 @@ int unit_skilluse_pos2( struct block_list *src, short skill_x, short skill_y, ui
  */
 int unit_set_target(struct unit_data* ud, int target_id)
 {
-	struct unit_data * ux;
-	struct block_list* target;
-
 	nullpo_ret(ud);
 
 	if( ud->target != target_id ) {
+		struct unit_data * ux;
+		struct block_list* target;
+	
 		if( ud->target && (target = map_id2bl(ud->target)) && (ux = unit_bl2ud(target)) && ux->target_count > 0 )
 			ux->target_count --;
 		if( target_id && (target = map_id2bl(target_id)) && (ux = unit_bl2ud(target)) )
@@ -1939,7 +1939,6 @@ bool unit_can_reach_pos(struct block_list *bl,int x,int y, int easy)
  */
 bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range, int easy, short *x, short *y)
 {
-	int i;
 	short dx,dy;
 	nullpo_retr(false, bl);
 	nullpo_retr(false, tbl);
@@ -1960,6 +1959,7 @@ bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range,
 	dy=(dy>0)?1:((dy<0)?-1:0);
 
 	if (map_getcell(tbl->m,tbl->x-dx,tbl->y-dy,CELL_CHKNOPASS)) { // Look for a suitable cell to place in.
+		int i;
 		for(i=0;i<9 && map_getcell(tbl->m,tbl->x-dirx[i],tbl->y-diry[i],CELL_CHKNOPASS);i++);
 		if (i==9) return false; // No valid cells.
 		dx = dirx[i];
@@ -1981,7 +1981,7 @@ bool unit_can_reach_bl(struct block_list *bl,struct block_list *tbl, int range,
  */
 int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir)
 {
-	int dx, dy, x, y, i, k;
+	int dx, dy, x, y;
 	struct unit_data *ud = unit_bl2ud(bl);
 	nullpo_ret(ud);
 
@@ -2001,8 +2001,9 @@ int unit_calc_pos(struct block_list *bl, int tx, int ty, uint8 dir)
 		if( dx > 0 ) x--; else if( dx < 0 ) x++;
 		if( dy > 0 ) y--; else if( dy < 0 ) y++;
 		if( !unit_can_reach_pos(bl, x, y, 0) ) {
+			int i;
 			for( i = 0; i < 12; i++ ) {
-				k = rnd()%8; // Pick a Random Dir
+				int k = rnd()%8; // Pick a Random Dir
 				dx = -dirx[k] * 2;
 				dy = -diry[k] * 2;
 				x = tx + dx;

+ 1 - 1
src/map/vending.c

@@ -293,7 +293,7 @@ void vending_openvending(struct map_session_data* sd, const char* message, const
 
 		sd->vending[i].index = index;
 		sd->vending[i].amount = amount;
-		sd->vending[i].value = cap_value(value, 0, (unsigned int)battle_config.vending_max_value);
+		sd->vending[i].value = min(value, (unsigned int)battle_config.vending_max_value);
 
 		i++; // item successfully added
 	}

+ 1 - 1
tools/convert_sql.pl

@@ -13,7 +13,7 @@
 #     --i=../db/re/mob_skill_db.txt --o=../sql-files/mob_skill_db_re.sql --t=re --m=mob_skill --table=mob_skill_db_re
 #
 # List of options:
-#   item_db.pl --help
+#   convert_sql.pl --help
 
 use strict;
 use warnings;