Browse Source

Major cleanup all over the place, made possible by mkbu95's scan-build report he provided us with.

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@16687 54d463be-8e91-2dee-dedb-b68131a5f0ec
shennetsind 12 years ago
parent
commit
1beef8ba89
14 changed files with 124 additions and 197 deletions
  1. 4 7
      src/char/char.c
  2. 2 3
      src/char/inter.c
  3. 3 3
      src/common/conf.c
  4. 7 6
      src/common/db.c
  5. 26 59
      src/common/grfio.c
  6. 4 4
      src/map/atcommand.c
  7. 1 4
      src/map/chrif.c
  8. 8 8
      src/map/clif.c
  9. 2 3
      src/map/elemental.c
  10. 0 1
      src/map/homunculus.c
  11. 9 21
      src/map/mob.c
  12. 3 5
      src/map/npc.c
  13. 4 4
      src/map/script.c
  14. 51 69
      src/map/skill.c

+ 4 - 7
src/char/char.c

@@ -3413,7 +3413,7 @@ void char_delete2_cancel_ack(int fd, int char_id, uint32 result)
 
 static void char_delete2_req(int fd, struct char_session_data* sd)
 {// CH: <0827>.W <char id>.L
-	int char_id, i, guild_id, party_id;
+	int char_id, i;
 	char* data;
 	time_t delete_date;
 
@@ -3426,19 +3426,16 @@ static void char_delete2_req(int fd, struct char_session_data* sd)
 		return;
 	}
 
-	if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `guild_id`,`party_id`,`delete_date` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) || SQL_SUCCESS != Sql_NextRow(sql_handle) )
+	if( SQL_SUCCESS != Sql_Query(sql_handle, "SELECT `delete_date` FROM `%s` WHERE `char_id`='%d'", char_db, char_id) || SQL_SUCCESS != Sql_NextRow(sql_handle) )
 	{
 		Sql_ShowDebug(sql_handle);
 		char_delete2_ack(fd, char_id, 3, 0);
 		return;
 	}
 	
-	Sql_GetData(sql_handle, 0, &data, NULL); guild_id = atoi(data);
-	Sql_GetData(sql_handle, 1, &data, NULL); party_id = atoi(data);
-	Sql_GetData(sql_handle, 2, &data, NULL); delete_date = strtoul(data, NULL, 10);
+	Sql_GetData(sql_handle, 0, &data, NULL); delete_date = strtoul(data, NULL, 10);
 	
-	if( delete_date )
-	{// character already queued for deletion
+	if( delete_date ) {// character already queued for deletion
 		char_delete2_ack(fd, char_id, 0, 0);
 		return;
 	}

+ 2 - 3
src/char/inter.c

@@ -378,11 +378,10 @@ const char * geoip_countryname[253] = {"Unknown","Asia/Pacific Region","Europe",
 unsigned char *geoip_cache;
 void geoip_readdb(void){
 	struct stat bufa;
-	size_t fileReadCount;
 	FILE *db=fopen("./db/GeoIP.dat","r");
 	fstat(fileno(db), &bufa);
 	geoip_cache = (unsigned char *) malloc(sizeof(unsigned char) * bufa.st_size);
-	fileReadCount = fread(geoip_cache, sizeof(unsigned char), bufa.st_size, db);
+	(void)fread(geoip_cache, sizeof(unsigned char), bufa.st_size, db);
 	fclose(db);
 	ShowStatus("Finished Reading "CL_GREEN"GeoIP"CL_RESET" Database.\n");
 }
@@ -392,7 +391,7 @@ const char* geoip_getcountry(uint32 ipnum){
 	int depth;
 	unsigned int x;
 	unsigned char stack_buffer[6];
-	const unsigned char *buf = stack_buffer;
+	const unsigned char *buf;
 	unsigned int offset = 0;
 		
 	for (depth = 31; depth >= 0; depth--) {

+ 3 - 3
src/common/conf.c

@@ -66,11 +66,11 @@ void config_setting_copy_elem(config_setting_t *parent, const config_setting_t *
 		set = config_setting_set_int64_elem(parent, -1, config_setting_get_int64(src));
 		config_setting_set_format(set, src->format);   
 	} else if (CONFIG_TYPE_FLOAT == config_setting_type(src)) {
-		set = config_setting_set_float_elem(parent, -1, config_setting_get_float(src));
+		config_setting_set_float_elem(parent, -1, config_setting_get_float(src));
 	} else if (CONFIG_TYPE_STRING == config_setting_type(src)) {
-		set = config_setting_set_string_elem(parent, -1, config_setting_get_string(src));
+		config_setting_set_string_elem(parent, -1, config_setting_get_string(src));
 	} else if (CONFIG_TYPE_BOOL == config_setting_type(src)) {
-		set = config_setting_set_bool_elem(parent, -1, config_setting_get_bool(src));
+		config_setting_set_bool_elem(parent, -1, config_setting_get_bool(src));
 	}
 }
 

+ 7 - 6
src/common/db.c

@@ -1538,9 +1538,8 @@ static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max,
 		// Match in the order: current node, left tree, right tree
 		node = db->ht[i];
 		while (node) {
-			parent = node->parent;
-			if (!(node->deleted))
-			{
+
+			if (!(node->deleted)) {
 				va_list argscopy;
 				va_copy(argscopy, args);
 				if (match(node->key, node->data, argscopy) == 0) {
@@ -1550,14 +1549,17 @@ static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max,
 				}
 				va_end(argscopy);
 			}
+			
 			if (node->left) {
 				node = node->left;
 				continue;
 			}
+			
 			if (node->right) {
 				node = node->right;
 				continue;
 			}
+			
 			while (node) {
 				parent = node->parent;
 				if (parent && parent->right && parent->left == node) {
@@ -1566,6 +1568,7 @@ static unsigned int db_obj_vgetall(DBMap* self, DBData **buf, unsigned int max,
 				}
 				node = parent;
 			}
+
 		}
 	}
 	db_free_unlock(db);
@@ -1923,9 +1926,7 @@ static int db_obj_vforeach(DBMap* self, DBApply func, va_list args)
 		// Apply func in the order: current node, left node, right node
 		node = db->ht[i];
 		while (node) {
-			parent = node->parent;
-			if (!(node->deleted))
-			{
+			if (!(node->deleted)) {
 				va_list argscopy;
 				va_copy(argscopy, args);
 				sum += func(node->key, &node->data, argscopy);

+ 26 - 59
src/common/grfio.c

@@ -391,29 +391,24 @@ void* grfio_reads(const char* fname, int* size)
 	unsigned char* buf2 = NULL;
 
 	FILELIST* entry = filelist_find(fname);
-	if( entry == NULL || entry->gentry <= 0 )
-	{// LocalFileCheck
+	if( entry == NULL || entry->gentry <= 0 ) {// LocalFileCheck
 		char lfname[256];
 		int declen;
 		FILE* in;
-		size_t fileReadCount;
 		grfio_localpath_create(lfname, sizeof(lfname), ( entry && entry->fnd ) ? entry->fnd : fname);
 
 		in = fopen(lfname, "rb");
-		if( in != NULL )
-		{
+		if( in != NULL ) {
 			fseek(in,0,SEEK_END);
 			declen = ftell(in);
 			fseek(in,0,SEEK_SET);
 			buf2 = (unsigned char *)aMalloc(declen+1);  // +1 for resnametable zero-termination
-			fileReadCount = fread(buf2, 1, declen, in);
+			(void)fread(buf2, 1, declen, in);
 			fclose(in);
 
 			if( size )
 				*size = declen;
-		}
-		else
-		{
+		} else {
 			if (entry != NULL && entry->gentry < 0) {
 				entry->gentry = -entry->gentry;	// local file checked
 			} else {
@@ -423,16 +418,13 @@ void* grfio_reads(const char* fname, int* size)
 		}
 	}
 
-	if( entry != NULL && entry->gentry > 0 )
-	{// Archive[GRF] File Read
+	if( entry != NULL && entry->gentry > 0 ) {// Archive[GRF] File Read
 		char* grfname = gentry_table[entry->gentry - 1];
 		FILE* in = fopen(grfname, "rb");
-		if( in != NULL )
-		{
+		if( in != NULL ) {
 			unsigned char *buf = (unsigned char *)aMalloc(entry->srclen_aligned);
-			size_t fileReadCount;
 			fseek(in, entry->srcpos, 0);
-			fileReadCount = fread(buf, 1, entry->srclen_aligned, in);
+			(void)fread(buf, 1, entry->srclen_aligned, in);
 			fclose(in);
 
 			buf2 = (unsigned char *)aMalloc(entry->declen+1);  // +1 for resnametable zero-termination
@@ -448,9 +440,7 @@ void* grfio_reads(const char* fname, int* size)
 					aFree(buf2);
 					return NULL;
 				}
-			}
-			else
-			{// directory?
+			} else {// directory?
 				memcpy(buf2, buf, entry->declen);
 			}
 
@@ -458,9 +448,7 @@ void* grfio_reads(const char* fname, int* size)
 				*size = entry->declen;
 
 			aFree(buf);
-		}
-		else
-		{
+		} else {
 			ShowError("grfio_reads: %s not found (GRF file: %s)\n", fname, grfname);
 			return NULL;
 		}
@@ -507,25 +495,20 @@ static int grfio_entryread(const char* grfname, int gentry)
 	unsigned char grf_header[0x2e];
 	int entry,entrys,ofs,grf_version;
 	unsigned char *grf_filelist;
-	size_t fileReadCount;
 
 	FILE* fp = fopen(grfname, "rb");
-	if( fp == NULL )
-	{
+	if( fp == NULL ) {
 		ShowWarning("GRF data file not found: '%s'\n",grfname);
 		return 1;	// 1:not found error
-	}
-	else
+	} else
 		ShowInfo("GRF data file found: '%s'\n",grfname);
 
 	fseek(fp,0,SEEK_END);
 	grf_size = ftell(fp);
 	fseek(fp,0,SEEK_SET);
 
-	fileReadCount = fread(grf_header,1,0x2e,fp);
-	if( strcmp((const char*)grf_header,"Master of Magic") != 0 ||
-		fseek(fp,getlong(grf_header+0x1e),SEEK_CUR) != 0 )
-	{
+	(void)fread(grf_header,1,0x2e,fp);
+	if( strcmp((const char*)grf_header,"Master of Magic") != 0 || fseek(fp,getlong(grf_header+0x1e),SEEK_CUR) != 0 ) {
 		fclose(fp);
 		ShowError("GRF %s read error\n", grfname);
 		return 2;	// 2:file format error
@@ -533,30 +516,25 @@ static int grfio_entryread(const char* grfname, int gentry)
 
 	grf_version = getlong(grf_header+0x2a) >> 8;
 
-	if( grf_version == 0x01 )
-	{// ****** Grf version 01xx ******
-		size_t fileReadCount;
+	if( grf_version == 0x01 ) {// ****** Grf version 01xx ******
 		list_size = grf_size - ftell(fp);
 		grf_filelist = (unsigned char *) aMalloc(list_size);
-		fileReadCount = fread(grf_filelist,1,list_size,fp);
+		(void)fread(grf_filelist,1,list_size,fp);
 		fclose(fp);
 
 		entrys = getlong(grf_header+0x26) - getlong(grf_header+0x22) - 7;
 
 		// Get an entry
-		for( entry = 0, ofs = 0; entry < entrys; ++entry )
-		{
+		for( entry = 0, ofs = 0; entry < entrys; ++entry ) {
 			FILELIST aentry;
 
 			int ofs2 = ofs+getlong(grf_filelist+ofs)+4;
 			unsigned char type = grf_filelist[ofs2+12];
-			if( type & FILELIST_TYPE_FILE )
-			{
+			if( type & FILELIST_TYPE_FILE ) {
 				char* fname = decode_filename(grf_filelist+ofs+6, grf_filelist[ofs]-6);
 				int srclen = getlong(grf_filelist+ofs2+0) - getlong(grf_filelist+ofs2+8) - 715;
 
-				if( strlen(fname) > sizeof(aentry.fn) - 1 )
-				{
+				if( strlen(fname) > sizeof(aentry.fn) - 1 ) {
 					ShowFatalError("GRF file name %s is too long\n", fname);
 					aFree(grf_filelist);
 					exit(EXIT_FAILURE);
@@ -583,21 +561,16 @@ static int grfio_entryread(const char* grfname, int gentry)
 		}
 
 		aFree(grf_filelist);
-	}
-	else
-	if( grf_version == 0x02 )
-	{// ****** Grf version 02xx ******
+	} else if( grf_version == 0x02 ) {// ****** Grf version 02xx ******
 		unsigned char eheader[8];
 		unsigned char *rBuf;
 		uLongf rSize, eSize;
-		size_t fileReadCount;
 
-		fileReadCount = fread(eheader,1,8,fp);
+		(void)fread(eheader,1,8,fp);
 		rSize = getlong(eheader);	// Read Size
 		eSize = getlong(eheader+4);	// Extend Size
 
-		if( (long)rSize > grf_size-ftell(fp) )
-		{
+		if( (long)rSize > grf_size-ftell(fp) ) {
 			fclose(fp);
 			ShowError("Illegal data format: GRF compress entry size\n");
 			return 4;
@@ -605,32 +578,28 @@ static int grfio_entryread(const char* grfname, int gentry)
 
 		rBuf = (unsigned char *)aMalloc(rSize);	// Get a Read Size
 		grf_filelist = (unsigned char *)aMalloc(eSize);	// Get a Extend Size
-		fileReadCount = fread(rBuf,1,rSize,fp);
+		(void)fread(rBuf,1,rSize,fp);
 		fclose(fp);
 		decode_zip(grf_filelist, &eSize, rBuf, rSize);	// Decode function
-		list_size = eSize;
 		aFree(rBuf);
 
 		entrys = getlong(grf_header+0x26) - 7;
 
 		// Get an entry
-		for( entry = 0, ofs = 0; entry < entrys; ++entry )
-		{
+		for( entry = 0, ofs = 0; entry < entrys; ++entry ) {
 			FILELIST aentry;
 
 			char* fname = (char*)(grf_filelist+ofs);
 			int ofs2 = ofs + (int)strlen(fname)+1;
 			int type = grf_filelist[ofs2+12];
 
-			if( strlen(fname) > sizeof(aentry.fn)-1 )
-			{
+			if( strlen(fname) > sizeof(aentry.fn)-1 ) {
 				ShowFatalError("GRF file name %s is too long\n", fname);
 				aFree(grf_filelist);
 				exit(EXIT_FAILURE);
 			}
 
-			if( type & FILELIST_TYPE_FILE )
-			{// file
+			if( type & FILELIST_TYPE_FILE ) {// file
 				aentry.srclen         = getlong(grf_filelist+ofs2+0);
 				aentry.srclen_aligned = getlong(grf_filelist+ofs2+4);
 				aentry.declen         = getlong(grf_filelist+ofs2+8);
@@ -650,9 +619,7 @@ static int grfio_entryread(const char* grfname, int gentry)
 		}
 
 		aFree(grf_filelist);
-	}
-	else
-	{// ****** Grf Other version ******
+	} else {// ****** Grf Other version ******
 		fclose(fp);
 		ShowError("GRF version %04x not supported\n",getlong(grf_header+0x2a));
 		return 4;

+ 4 - 4
src/map/atcommand.c

@@ -2406,14 +2406,14 @@ ACMD_FUNC(produce)
 		return -1;
 	}
 
-	item_id = 0;
-	if ((item_data = itemdb_searchname(item_name)) == NULL &&
-	    (item_data = itemdb_exists(atoi(item_name))) == NULL)
-	{
+	if ( (item_data = itemdb_searchname(item_name)) == NULL &&
+		 (item_data = itemdb_exists(atoi(item_name))) == NULL ) {
 		clif_displaymessage(fd, msg_txt(170)); //This item is not an equipment.
 		return -1;
 	}
+	
 	item_id = item_data->nameid;
+	
 	if (itemdb_isequip2(item_data)) {
 		if (attribute < MIN_ATTRIBUTE || attribute > MAX_ATTRIBUTE)
 			attribute = ATTRIBUTE_NORMAL;

+ 1 - 4
src/map/chrif.c

@@ -647,20 +647,17 @@ void chrif_authok(int fd)
 }
 
 // client authentication failed
-void chrif_authfail(int fd)
-{
+void chrif_authfail(int fd) {/* HELLO WORLD. ip in RFIFOL 15 is not being used (but is available) */
 	int account_id;
 	int char_id;
 	uint32 login_id1;
 	char sex;
-	uint32 ip;
 	struct auth_node* node;
 
 	account_id = RFIFOL(fd,2);
 	char_id    = RFIFOL(fd,6);
 	login_id1  = RFIFOL(fd,10);
 	sex        = RFIFOB(fd,14);
-	ip         = ntohl(RFIFOL(fd,15));
 
 	node = chrif_search(account_id);
 	if( node != NULL &&

+ 8 - 8
src/map/clif.c

@@ -3054,8 +3054,8 @@ void clif_changelook(struct block_list *bl,int type,int val)
 						val = sd->inventory_data[n]->view_id;
 					else
 						val = sd->status.inventory[n].nameid;
-					}
-				val = 0;
+				} else
+					val = 0;
 			}
 #endif
 			//Shoes? No packet uses this....
@@ -10047,14 +10047,14 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
 /// /b /nb (CZ_BROADCAST).
 /// Request to broadcast a message on whole server.
 /// 0099 <packet len>.W <text>.?B 00
-void clif_parse_Broadcast(int fd, struct map_session_data* sd)
-{
+void clif_parse_Broadcast(int fd, struct map_session_data* sd) {
 	char command[CHAT_SIZE_MAX+11];
 	char* msg = (char*)RFIFOP(fd,4);
 	unsigned int len = RFIFOW(fd,2)-4;
 
 	// as the length varies depending on the command used, just block unreasonably long strings
-	len = mes_len_check(msg, len, CHAT_SIZE_MAX);
+	mes_len_check(msg, len, CHAT_SIZE_MAX);
+	
 	sprintf(command, "%ckami %s", atcommand_symbol, msg);
 	is_atcommand(fd, sd, command, 1);
 }
@@ -11248,7 +11248,7 @@ void clif_parse_LocalBroadcast(int fd, struct map_session_data* sd)
 	unsigned int len = RFIFOW(fd,2)-4;
 	
 	// as the length varies depending on the command used, just block unreasonably long strings
-	len = mes_len_check(msg, len, CHAT_SIZE_MAX);
+	mes_len_check(msg, len, CHAT_SIZE_MAX);
 
 	sprintf(command, "%clkami %s", atcommand_symbol, msg);
 	is_atcommand(fd, sd, command, 1);
@@ -12919,11 +12919,11 @@ void clif_parse_FriendsListAdd(int fd, struct map_session_data *sd)
 void clif_parse_FriendsListReply(int fd, struct map_session_data *sd)
 {
 	struct map_session_data *f_sd;
-	int char_id, account_id;
+	int account_id;
 	char reply;
 
 	account_id = RFIFOL(fd,2);
-	char_id = RFIFOL(fd,6);
+	//char_id = RFIFOL(fd,6);
 #if PACKETVER < 6
 	reply = RFIFOB(fd,10);
 #else

+ 2 - 3
src/map/elemental.c

@@ -605,14 +605,14 @@ static int elemental_ai_sub_timer(struct elemental_data *ed, struct map_session_
 		target = map_id2bl(ed->ud.target);
 		
 		if( !target )
-			map_foreachinrange(elemental_ai_sub_timer_activesearch, &ed->bl, ed->db->range2, BL_CHAR, ed, &target, status_get_mode(&ed->bl));
+			map_foreachinrange(elemental_ai_sub_timer_activesearch, &ed->bl, view_range, BL_CHAR, ed, &target, status_get_mode(&ed->bl));
 		
 		if( !target ) { //No targets available.
 			elemental_unlocktarget(ed);
 			return 1;
 		}
 		
-		if( battle_check_range(&ed->bl,target,ed->db->range2) && rnd()%100 < 2 ) { // 2% chance to cast attack skill.
+		if( battle_check_range(&ed->bl,target,view_range) && rnd()%100 < 2 ) { // 2% chance to cast attack skill.
 			if(	elemental_action(ed,target,tick) )
 				return 1;
 		}
@@ -786,7 +786,6 @@ int read_elemental_skilldb(void) {
 		skillmode = atoi(str[3]);
 		if( skillmode < EL_SKILLMODE_PASIVE || skillmode > EL_SKILLMODE_AGGRESSIVE ) {
 			ShowError("read_elemental_skilldb : Skillmode out of range, line %d.\n",k);
-			skillmode = EL_SKILLMODE_PASIVE;
 			continue;
 		}
 		ARR_FIND( 0, MAX_ELESKILLTREE, i, db->skill[i].id == 0 || db->skill[i].id == skillid );

+ 0 - 1
src/map/homunculus.c

@@ -183,7 +183,6 @@ int merc_hom_calc_skilltree(struct homun_data *hd)
 		}
 		
 		f = 1;
-		id = c = 0;
 	}
 	
 	c = hd->homunculus.class_ - HM_CLASS_BASE;

+ 9 - 21
src/map/mob.c

@@ -1189,16 +1189,13 @@ static int mob_ai_sub_hard_lootsearch(struct block_list *bl,va_list ap)
 	return 0;
 }
 
-static int mob_warpchase_sub(struct block_list *bl,va_list ap)
-{
-	struct mob_data* md;
+static int mob_warpchase_sub(struct block_list *bl,va_list ap) {
 	struct block_list *target;
 	struct npc_data **target_nd;
 	struct npc_data *nd;
 	int *min_distance;
 	int cur_distance;
 
-	md=va_arg(ap,struct mob_data *);
 	target= va_arg(ap, struct block_list*);
 	target_nd= va_arg(ap, struct npc_data**);
 	min_distance= va_arg(ap, int*);
@@ -1410,7 +1407,7 @@ int mob_warpchase(struct mob_data *md, struct block_list *target)
 
 	//Search for warps within mob's viewing range.
 	map_foreachinrange (mob_warpchase_sub, &md->bl,
-		md->db->range2, BL_NPC, md, target, &warp, &distance);
+		md->db->range2, BL_NPC, target, &warp, &distance);
 
 	if (warp && unit_walktobl(&md->bl, &warp->bl, 1, 1))
 		return 1;
@@ -3903,20 +3900,17 @@ static int mob_read_sqldb(void)
 	const char* mob_db_name[] = { mob_db_db, mob_db2_db };
 	int fi;
 	
-	for( fi = 0; fi < ARRAYLENGTH(mob_db_name); ++fi )
-	{
+	for( fi = 0; fi < ARRAYLENGTH(mob_db_name); ++fi ) {
 		uint32 lines = 0, count = 0;
 		
 		// retrieve all rows from the mob database
-		if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", mob_db_name[fi]) )
-		{
+		if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", mob_db_name[fi]) ) {
 			Sql_ShowDebug(mmysql_handle);
 			continue;
 		}
 		
 		// process rows one by one
-		while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) )
-		{
+		while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ) {
 			// wrap the result into a TXT-compatible format
 			char line[1024];
 			char* str[31+2*MAX_MVP_DROP+2*MAX_MOB_DROP];
@@ -3945,7 +3939,6 @@ static int mob_read_sqldb(void)
 		Sql_FreeResult(mmysql_handle);
 		
 		ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, mob_db_name[fi]);
-		count = 0;
 	}
 	return 0;
 }
@@ -4476,27 +4469,23 @@ static int mob_read_sqlskilldb(void)
 	const char* mob_skill_db_name[] = { mob_skill_db_db, mob_skill_db2_db };
 	int fi;
 	
-	if( battle_config.mob_skill_rate == 0 )
-	{
+	if( battle_config.mob_skill_rate == 0 ) {
 		ShowStatus("Mob skill use disabled. Not reading mob skills.\n");
 		return 0;
 	}
 
 
-	for( fi = 0; fi < ARRAYLENGTH(mob_skill_db_name); ++fi )
-	{
+	for( fi = 0; fi < ARRAYLENGTH(mob_skill_db_name); ++fi ) {
 		uint32 lines = 0, count = 0;
 		
 		// retrieve all rows from the mob skill database
-		if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", mob_skill_db_name[fi]) )
-		{
+		if( SQL_ERROR == Sql_Query(mmysql_handle, "SELECT * FROM `%s`", mob_skill_db_name[fi]) ) {
 			Sql_ShowDebug(mmysql_handle);
 			continue;
 		}
 		
 		// process rows one by one
-		while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) )
-		{
+		while( SQL_SUCCESS == Sql_NextRow(mmysql_handle) ) {
 			// wrap the result into a TXT-compatible format
 			char* str[19];
 			char* dummy = "";
@@ -4518,7 +4507,6 @@ static int mob_read_sqlskilldb(void)
 		Sql_FreeResult(mmysql_handle);
 		
 		ShowStatus("Done reading '"CL_WHITE"%lu"CL_RESET"' entries in '"CL_WHITE"%s"CL_RESET"'.\n", count, mob_skill_db_name[fi]);
-		count = 0;
 	}
 	return 0;
 }

+ 3 - 5
src/map/npc.c

@@ -814,14 +814,13 @@ int npc_event(struct map_session_data* sd, const char* eventname, int ontouch)
 int npc_touch_areanpc_sub(struct block_list *bl, va_list ap)
 {
 	struct map_session_data *sd;
-	int pc_id,npc_id;
+	int pc_id;
 	char *name;
 
 	nullpo_ret(bl);
 	nullpo_ret((sd = map_id2sd(bl->id)));
 
 	pc_id = va_arg(ap,int);
-	npc_id = va_arg(ap,int);
 	name = va_arg(ap,char*);
 
 	if( pc_ishiding(sd) )
@@ -854,7 +853,7 @@ int npc_touchnext_areanpc(struct map_session_data* sd, bool leavemap)
 
 		nd->touching_id = sd->touching_id = 0;
 		snprintf(name, ARRAYLENGTH(name), "%s::%s", nd->exname, script_config.ontouch_name);
-		map_forcountinarea(npc_touch_areanpc_sub,nd->bl.m,nd->bl.x - xs,nd->bl.y - ys,nd->bl.x + xs,nd->bl.y + ys,1,BL_PC,sd->bl.id,nd->bl.id,name);
+		map_forcountinarea(npc_touch_areanpc_sub,nd->bl.m,nd->bl.x - xs,nd->bl.y - ys,nd->bl.x + xs,nd->bl.y + ys,1,BL_PC,sd->bl.id,name);
 	}
 	return 0;
 }
@@ -1649,11 +1648,10 @@ int npc_selllist(struct map_session_data* sd, int n, unsigned short* item_list)
 	// delete items
 	for( i = 0; i < n; i++ )
 	{
-		int nameid, amount, idx;
+		int amount, idx;
 
 		idx    = item_list[i*2]-2;
 		amount = item_list[i*2+1];
-		nameid = sd->status.inventory[idx].nameid;
 
 		if( sd->inventory_data[idx]->type == IT_PETEGG && sd->status.inventory[idx].card[0] == CARD0_PET )
 		{

+ 4 - 4
src/map/script.c

@@ -1328,15 +1328,15 @@ const char* parse_subexpr(const char* p,int limit)
 
 	p=skip_space(p);
 
-	if(*p=='-'){
-		tmpp=skip_space(p+1);
-		if(*tmpp==';' || *tmpp==','){
+	if( *p == '-' ){
+		 tmpp = skip_space(p+1);
+		if( *tmpp == ';' || *tmpp == ',' ){
 			add_scriptl(LABEL_NEXTLINE);
 			p++;
 			return p;
 		}
 	}
-	tmpp=p;
+
 	if((op=C_NEG,*p=='-') || (op=C_LNOT,*p=='!') || (op=C_NOT,*p=='~')){
 		p=parse_subexpr(p+1,10);
 		add_scriptc(op);

+ 51 - 69
src/map/skill.c

@@ -1928,7 +1928,7 @@ int skill_break_equip (struct block_list *bl, unsigned short where, int rate, in
 			j = sd->equip_index[i];
 			if (j < 0 || sd->status.inventory[j].attribute == 1 || !sd->inventory_data[j])
 				continue;
-			flag = 0;
+
 			switch(i) {
 				case EQI_HEAD_TOP: //Upper Head
 					flag = (where&EQP_HELM);
@@ -7383,7 +7383,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
 			i = skill_get_splash(skillid,skilllv);
 			if( skillid == LG_EARTHDRIVE ) {
 				int dummy = 1;
-				map_foreachinarea(skill_cell_overlap, src->m, src->x-i, src->y-i, src->x+i, src->y+i, BL_SKILL, LG_EARTHDRIVE, &dummy, src);
+				map_foreachinarea(skill_cell_overlap, src->m, src->x-i, src->y-i, src->x+i, src->y+i, BL_SKILL, LG_EARTHDRIVE, src);
 			}
 			map_foreachinrange(skill_area_sub, bl,i,BL_CHAR,
 				src,skillid,skilllv,tick,flag|BCT_ENEMY|1,skill_castend_damage_id);
@@ -7760,8 +7760,7 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
 		if( status_isimmune(bl) || !tsc )
 			break;
 
-		if( flag&1 )
-		{
+		if( flag&1 ) {
 			if( bl->id == skill_area_temp[1] )
 				break; // Already work on this target
 
@@ -7769,24 +7768,18 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, in
 				status_change_end(bl,SC_STONE,INVALID_TIMER);
 			else
 				status_change_start(bl,SC_STONE,10000,skilllv,0,0,1000,(8+2*skilllv)*1000,2);
-		}
-		else
-		{
+		} else {
 			int rate = 40 + 8 * skilllv + ( sd? sd->status.job_level : 50 ) / 4;
 			// IroWiki says Rate should be reduced by target stats, but currently unknown
-			if( rnd()%100 < rate )
-			{ // Success on First Target
-				rate = 0;
+			if( rnd()%100 < rate ) { // Success on First Target
 				if( !tsc->data[SC_STONE] )
 					rate = status_change_start(bl,SC_STONE,10000,skilllv,0,0,1000,(8+2*skilllv)*1000,2);
-				else
-				{
+				else {
 					rate = 1;
 					status_change_end(bl,SC_STONE,INVALID_TIMER);
 				}
 
-				if( rate )
-				{
+				if( rate ) {
 					skill_area_temp[1] = bl->id;
 					map_foreachinrange(skill_area_sub,bl,skill_get_splash(skillid,skilllv),BL_CHAR,src,skillid,skilllv,tick,flag|BCT_ENEMY|1,skill_castend_nodamage_id);
 				}
@@ -9740,7 +9733,7 @@ int skill_castend_pos2(struct block_list* src, int x, int y, int skillid, int sk
 			int dummy = 1;
 			clif_skill_poseffect(src,skillid,skilllv,x,y,tick);
 			i = skill_get_splash(skillid, skilllv);
-			map_foreachinarea(skill_cell_overlap, src->m, x-i, y-i, x+i, y+i, BL_SKILL, HW_GANBANTEIN, &dummy, src);
+			map_foreachinarea(skill_cell_overlap, src->m, x-i, y-i, x+i, y+i, BL_SKILL, HW_GANBANTEIN, src);
 		} else {
 			if (sd) clif_skill_fail(sd,skillid,USESKILL_FAIL_LEVEL,0);
 			return 1;
@@ -10738,7 +10731,7 @@ struct skill_unit_group* skill_unitsetting (struct block_list *src, short skilli
 		}
 
 		if( range <= 0 )
-			map_foreachincell(skill_cell_overlap,src->m,ux,uy,BL_SKILL,skillid,&alive, src);
+			map_foreachincell(skill_cell_overlap,src->m,ux,uy,BL_SKILL,skillid, src);
 		if( !alive )
 			continue;
 
@@ -10867,7 +10860,6 @@ static int skill_unit_onplace (struct skill_unit *src, struct block_list *bl, un
 				sg->val1 = (count<<16)|working;
 				
 				pc_setpos(sd,m,x,y,CLR_TELEPORT);
-				sg = src->group; // avoid dangling pointer (pc_setpos can cause deletion of 'sg')
 			}
 		} else if(bl->type == BL_MOB && battle_config.mob_warp&2) {
 			int m = map_mapindex2mapid(sg->val3);
@@ -11212,17 +11204,15 @@ int skill_unit_onplace_timer (struct skill_unit *src, struct block_list *bl, uns
 
 		case UNT_ELECTRICSHOCKER:
 			if( bl->id != ss->id ) {
-				int sec = skill_get_time2(sg->skill_id, sg->skill_lv);
 				if( status_get_mode(bl)&MD_BOSS )
 					break;
-				if( status_change_start(bl,type,10000,sg->skill_lv,sg->group_id,0,0,sec, 8) ) {
-					const struct TimerData* td = tsc->data[type]?get_timer(tsc->data[type]->timer):NULL;
-					if( td ) 
-						sec = DIFF_TICK(td->tick, tick);
+				if( status_change_start(bl,type,10000,sg->skill_lv,sg->group_id,0,0,skill_get_time2(sg->skill_id, sg->skill_lv), 8) ) {
+
 					map_moveblock(bl, src->bl.x, src->bl.y, tick);
 					clif_fixpos(bl);
-				} else
-					sec = 3000; //Couldn't trap it?
+				
+				}
+				
 				map_foreachinrange(skill_trap_splash, &src->bl, skill_get_splash(sg->skill_id, sg->skill_lv), sg->bl_flag, &src->bl, tick);
 				sg->unit_id = UNT_USED_TRAPS; //Changed ID so it does not invoke a for each in area again.
 			}			
@@ -12994,17 +12984,13 @@ int skill_check_condition_castend(struct map_session_data* sd, short skill, shor
 			if( skill == NC_MAGICDECOY )
 				mob_class = 2043;
 
-			if( battle_config.land_skill_limit && maxcount > 0 && ( battle_config.land_skill_limit&BL_PC ) )
-			{
-				if( skill == NC_MAGICDECOY )
-				{
+			if( battle_config.land_skill_limit && maxcount > 0 && ( battle_config.land_skill_limit&BL_PC ) ) {
+				if( skill == NC_MAGICDECOY ) {
 					for( j = mob_class; j <= 2046; j++ )
-						i = map_foreachinmap(skill_check_condition_mob_master_sub, sd->bl.m, BL_MOB, sd->bl.id, j, skill, &c);
-				}
-				else
-					i = map_foreachinmap(skill_check_condition_mob_master_sub, sd->bl.m, BL_MOB, sd->bl.id, mob_class, skill, &c);
-				if( c >= maxcount )
-				{
+						map_foreachinmap(skill_check_condition_mob_master_sub, sd->bl.m, BL_MOB, sd->bl.id, j, skill, &c);
+				} else
+					map_foreachinmap(skill_check_condition_mob_master_sub, sd->bl.m, BL_MOB, sd->bl.id, mob_class, skill, &c);
+				if( c >= maxcount ) {
 					clif_skill_fail(sd , skill, USESKILL_FAIL_LEVEL, 0);
 					return 0;
 				}
@@ -13382,37 +13368,41 @@ struct skill_condition skill_get_requirement(struct map_session_data* sd, short
 /*==========================================
  * Does cast-time reductions based on dex, item bonuses and config setting
  *------------------------------------------*/
-int skill_castfix (struct block_list *bl, int skill_id, int skill_lv)
-{
+int skill_castfix (struct block_list *bl, int skill_id, int skill_lv) {
 	int time = skill_get_cast(skill_id, skill_lv);
-	struct map_session_data *sd;
 
 	nullpo_ret(bl);
-	sd = BL_CAST(BL_PC, bl);
 #ifndef RENEWAL_CAST
-	// calculate base cast time (reduced by dex)
-	if( !(skill_get_castnodex(skill_id, skill_lv)&1) ) {
-		int scale = battle_config.castrate_dex_scale - status_get_dex(bl);
-		if( scale > 0 )	// not instant cast
-			time = time * scale / battle_config.castrate_dex_scale;
-		else
-			return 0;	// instant cast
-	}
-
-	// calculate cast time reduced by item/card bonuses
-	if( !(skill_get_castnodex(skill_id, skill_lv)&4) && sd )
 	{
-		int i;
-		if( sd->castrate != 100 )
-			time = time * sd->castrate / 100;
-		for( i = 0; i < ARRAYLENGTH(sd->skillcast) && sd->skillcast[i].id; i++ )
+		struct map_session_data *sd;
+
+		sd = BL_CAST(BL_PC, bl);
+
+		// calculate base cast time (reduced by dex)
+		if( !(skill_get_castnodex(skill_id, skill_lv)&1) ) {
+			int scale = battle_config.castrate_dex_scale - status_get_dex(bl);
+			if( scale > 0 )	// not instant cast
+				time = time * scale / battle_config.castrate_dex_scale;
+			else
+				return 0;	// instant cast
+		}
+
+		// calculate cast time reduced by item/card bonuses
+		if( !(skill_get_castnodex(skill_id, skill_lv)&4) && sd )
 		{
-			if( sd->skillcast[i].id == skill_id )
+			int i;
+			if( sd->castrate != 100 )
+				time = time * sd->castrate / 100;
+			for( i = 0; i < ARRAYLENGTH(sd->skillcast) && sd->skillcast[i].id; i++ )
 			{
-				time+= time * sd->skillcast[i].val / 100;
-				break;
+				if( sd->skillcast[i].id == skill_id )
+				{
+					time+= time * sd->skillcast[i].val / 100;
+					break;
+				}
 			}
 		}
+		
 	}
 #endif
 	// config cast time multiplier
@@ -14328,27 +14318,22 @@ static int skill_cell_overlap(struct block_list *bl, va_list ap)
 	int skillid;
 	int *alive;
 	struct skill_unit *unit;
-	struct block_list *src;
 
 	skillid = va_arg(ap,int);
 	alive = va_arg(ap,int *);
-	src = va_arg(ap,struct block_list *);
 	unit = (struct skill_unit *)bl;
 
 	if (unit == NULL || unit->group == NULL || (*alive) == 0)
 		return 0;
 
-	switch (skillid)
-	{
+	switch (skillid) {
 		case SA_LANDPROTECTOR:
-			if( unit->group->skill_id == SA_LANDPROTECTOR )
-			{	//Check for offensive Land Protector to delete both. [Skotlex]
+			if( unit->group->skill_id == SA_LANDPROTECTOR ) {//Check for offensive Land Protector to delete both. [Skotlex]
 				(*alive) = 0;
 				skill_delunit(unit);
 				return 1;
 			}
-			if( !(skill_get_inf2(unit->group->skill_id)&(INF2_SONG_DANCE|INF2_TRAP)) )
-			{	//It deletes everything except songs/dances and traps
+			if( !(skill_get_inf2(unit->group->skill_id)&(INF2_SONG_DANCE|INF2_TRAP)) ) { //It deletes everything except songs/dances and traps
 				skill_delunit(unit);
 				return 1;
 			}
@@ -14383,8 +14368,7 @@ static int skill_cell_overlap(struct block_list *bl, va_list ap)
 */
 			break;
 		case PF_FOGWALL:
-			switch(unit->group->skill_id)
-			{
+			switch(unit->group->skill_id) {
 				case SA_VOLCANO: //Can't be placed on top of these
 				case SA_VIOLENTGALE:
 					(*alive) = 0;
@@ -14405,9 +14389,7 @@ static int skill_cell_overlap(struct block_list *bl, va_list ap)
 			break;
 	}
 
-	if (unit->group->skill_id == SA_LANDPROTECTOR &&
-		!(skill_get_inf2(skillid)&(INF2_SONG_DANCE|INF2_TRAP)))
-	{	//It deletes everything except songs/dances/traps
+	if (unit->group->skill_id == SA_LANDPROTECTOR && !(skill_get_inf2(skillid)&(INF2_SONG_DANCE|INF2_TRAP))) {	//It deletes everything except songs/dances/traps
 		(*alive) = 0;
 		return 1;
 	}