Browse Source

[Optimized]
- Removed unused checks for unsigned data type and possible logic error for char type (gcc treats char as unsigned).

git-svn-id: https://svn.code.sf.net/p/rathena/svn/trunk@6814 54d463be-8e91-2dee-dedb-b68131a5f0ec

Lance 19 years ago
parent
commit
a28e9d802c

+ 3 - 0
Changelog-Trunk.txt

@@ -4,6 +4,9 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK.  ALL UNTESTED BUGFIXES/FEATURES GO
 IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK.
 
 2006/05/29
+	* [Optimized]:
+	  - Removed unused checks for unsigned data type and possible logic error for
+	    char type (gcc treats char as unsigned). [Lance]
 	* [Fixed]:
 	  - Relogging in with 0 HP didn't trigger dead event. [Lance]
 2006/05/28

+ 1 - 1
src/common/grfio.c

@@ -68,7 +68,7 @@ typedef struct {
 	char	type;
 	char	fn[128-4*5];		// file name
 	char	*fnd;
-	char	gentry;				// read grf file select
+	signed char	gentry;				// read grf file select
 } FILELIST;
 //gentry ... 0    : It acquires from a local file.
 //             It acquires from the resource file of 1>=:gentry_table[gentry-1].

+ 1 - 1
src/common/showmsg.c

@@ -52,7 +52,7 @@ int _vShowMessage(enum msg_type flag, const char *string, va_list ap)
 		return 1;
 	}
 
-	if (timestamp_format)
+	if (strlen(timestamp_format) > 0)
 	{	//Display time format. [Skotlex]
 		time_t t = time(NULL);
 		strftime(prefix, 80, timestamp_format, localtime(&t));

+ 1 - 1
src/common/socket.c

@@ -1210,7 +1210,7 @@ int RFIFOSKIP(int fd,int len)
 
 	s = session[fd];
 
-	if (s->rdata_size-s->rdata_pos-len<0) {
+	if ((signed int)(s->rdata_size-s->rdata_pos-len)<0) {
 		//fprintf(stderr,"too many skip\n");
 		//exit(1);
 		//better than a COMPLETE program abort // TEST! :)

+ 2 - 5
src/map/atcommand.c

@@ -2466,7 +2466,7 @@ int atcommand_kami(
 			return -1;
 		}
 	
-		if(color < 0 || color > 0xFFFFFF) {
+		if(color > 0xFFFFFF) {
 			clif_displaymessage(fd, "Invalid color.");
 			return -1;
 		}
@@ -6199,9 +6199,6 @@ char * txt_time(unsigned int duration) {
 	memset(temp, '\0', sizeof(temp));
 	memset(temp1, '\0', sizeof(temp1));
 
-	if (duration < 0)
-		duration = 0;
-
 	days = duration / (60 * 60 * 24);
 	duration = duration - (60 * 60 * 24 * days);
 	hours = duration / (60 * 60);
@@ -7770,7 +7767,7 @@ int atcommand_autoloot(const int fd, struct map_session_data* sd, const char* co
 	rate = atoi(message) * 100;
 
 	// check for invalid value
-	if(rate < 0 || rate > 10000)
+	if(rate > 10000)
 	{
 		clif_displaymessage(fd, "Invalid value. Choose value between 0 and 100.");
 		return 0;

+ 1 - 1
src/map/battle.c

@@ -1614,7 +1614,7 @@ static struct Damage battle_calc_weapon_attack(
 		if (!flag.idef || !flag.idef2)
 		{	//Defense reduction
 			short vit_def;
-			char def1 = (char)status_get_def(target); //Don't use tstatus->def1 due to skill timer reductions.
+			signed char def1 = (signed char)status_get_def(target); //Don't use tstatus->def1 due to skill timer reductions.
 			short def2 = (short)tstatus->def2;
 			if(battle_config.vit_penalty_type)
 			{

+ 1 - 1
src/map/irc.c

@@ -129,7 +129,7 @@ void irc_announce_mvp(struct map_session_data *sd, struct mob_data *md)
 
 	memset(send_string,'\0',256);
 	memset(mapname,'\0',16);
-	mapname[16]='\0';
+	mapname[15]='\0'; // 15 is the final index, not 16 [Lance]
 	strcpy(mapname, map[md->bl.m].name);
 	maplen = strcspn(mapname,".");
 	mapname[maplen] = '\0';

+ 1 - 1
src/map/map.c

@@ -2162,7 +2162,7 @@ int map_getcell(int m,int x,int y,cell_t cellchk)
 	return (m < 0 || m >= MAX_MAP_PER_SERVER) ? 0 : map_getcellp(&map[m],x,y,cellchk);
 }
 
-int map_getcellp(struct map_data* m,int x,int y,cell_t cellchk)
+int map_getcellp(struct map_data* m,int x,int y,int cellchk)
 {
 	int type, type2;
 #ifdef CELL_NOSTACK

+ 2 - 1
src/map/npc.c

@@ -15,6 +15,7 @@
 #include "../common/grfio.h"
 #include "../common/showmsg.h"
 #include "../common/ers.h"
+#include "../common/db.h"
 #include "map.h"
 #include "log.h"
 #include "npc.h"
@@ -2193,7 +2194,7 @@ int npc_parse_mob (char *w1, char *w2, char *w3, char *w4)
 	if (sscanf(w3, "%23[^,],%d", mobname, &level) > 1)
 		mob.level = level;
 
-	if( mob.delay1<0 || mob.delay2<0 || mob.delay1>0xfffffff || mob.delay2>0xfffffff) {
+	if(mob.delay1>0xfffffff || mob.delay2>0xfffffff) {
 		ShowError("wrong monsters spawn delays : %s %s (file %s)\n", w3, w4, current_file);
 		return 1;
 	}

+ 2 - 6
src/map/pc.c

@@ -3842,7 +3842,7 @@ int pc_gainexp(struct map_session_data *sd,unsigned int base_exp,unsigned int jo
 	//Overflow checks... think we'll ever really need'em? [Skotlex]
 	if (base_exp > 0 && sd->status.base_exp > UINT_MAX - base_exp)
 		sd->status.base_exp = UINT_MAX;
-	else if (base_exp < 0 && sd->status.base_exp > base_exp)
+	else if (sd->status.base_exp > base_exp)
 		sd->status.base_exp = 0;
 	else
 		sd->status.base_exp += base_exp;
@@ -3854,7 +3854,7 @@ int pc_gainexp(struct map_session_data *sd,unsigned int base_exp,unsigned int jo
 	//Overflow checks... think we'll ever really need'em? [Skotlex]
 	if (job_exp > 0 && sd->status.job_exp > UINT_MAX - job_exp)
 		sd->status.job_exp = UINT_MAX;
-	else if (job_exp < 0 && sd->status.job_exp > job_exp)
+	else if (sd->status.job_exp > job_exp)
 		sd->status.job_exp = 0;
 	else
 		sd->status.job_exp += job_exp;
@@ -4933,16 +4933,12 @@ int pc_setparam(struct map_session_data *sd,int type,int val)
 	case SP_BASEEXP:
 		if(pc_nextbaseexp(sd) > 0) {
 			sd->status.base_exp = val;
-			if(sd->status.base_exp < 0)
-				sd->status.base_exp=0;
 			pc_checkbaselevelup(sd);
 		}
 		break;
 	case SP_JOBEXP:
 		if(pc_nextjobexp(sd) > 0) {
 			sd->status.job_exp = val;
-			if(sd->status.job_exp < 0)
-				sd->status.job_exp=0;
 			pc_checkjoblevelup(sd);
 		}
 		break;

+ 1 - 1
src/map/script.c

@@ -8171,7 +8171,7 @@ int buildin_petskillbonus(struct script_state *st)
 	pd->bonus->duration=conv_num(st,& (st->stack->stack_data[st->start+4]));
 	pd->bonus->delay=conv_num(st,& (st->stack->stack_data[st->start+5]));
 
-	if (pd->state.skillbonus == -1)
+	if (pd->state.skillbonus == 1)
 		pd->state.skillbonus=0;	// waiting state
 
 	// wait for timer to start

+ 1 - 1
src/map/status.c

@@ -629,7 +629,7 @@ int status_heal(struct block_list *bl,unsigned int hp,unsigned int sp, int flag)
 //If rates are > 0, percent is of current HP/SP
 //If rates are < 0, percent is of max HP/SP
 //If flag, this is heal, otherwise it is damage.
-int status_percent_change(struct block_list *src,struct block_list *target,char hp_rate, char sp_rate, int flag)
+int status_percent_change(struct block_list *src,struct block_list *target,signed char hp_rate, signed char sp_rate, int flag)
 {
 	struct status_data *status;
 	unsigned int hp  =0, sp = 0;

+ 1 - 1
src/map/status.h

@@ -508,7 +508,7 @@ int status_damage(struct block_list *src,struct block_list *target,unsigned int
 #define status_zap(bl, hp, sp) status_damage(NULL, bl, hp, sp, 0, 1)
 //Define for standard HP/SP skill-related cost triggers (mobs require no HP/SP to use skills)
 #define status_charge(bl, hp, sp) ((bl)->type != BL_PC || status_damage(NULL, bl, hp, sp, 0, 3))
-int status_percent_change(struct block_list *src,struct block_list *target,char hp_rate, char sp_rate, int flag);
+int status_percent_change(struct block_list *src,struct block_list *target,signed char hp_rate, signed char sp_rate, int flag);
 //Easier handling of status_percent_change
 #define status_percent_heal(bl, hp_rate, sp_rate) status_percent_change(NULL, bl, -(hp_rate), -(sp_rate), 1)
 #define status_percent_damage(src, target, hp_rate, sp_rate) status_percent_change(src, target, hp_rate, sp_rate, 0)

+ 1 - 1
src/map/vending.c

@@ -240,7 +240,7 @@ void vending_openvending(struct map_session_data *sd,int len,char *message,int f
 			else if(sd->vending[i].value < 1)
 				sd->vending[i].value = 1000000;	// auto set to 1 million [celest]
 			// カート内のアイテム数と販売するアイテム数に相違があったら中止
-			if(pc_cartitem_amount(sd, sd->vending[i].index, sd->vending[i].amount) < 0 || sd->vending[i].value < 0) { // fixes by Valaris and fritz
+			if(pc_cartitem_amount(sd, sd->vending[i].index, sd->vending[i].amount) < 0) { // fixes by Valaris and fritz
 				clif_skill_fail(sd, MC_VENDING, 0, 0);
 				return;
 			}