diff options
author | Haru <haru@dotalux.com> | 2016-02-19 14:53:45 +0100 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2016-03-20 18:32:06 +0100 |
commit | 3ce598dc1ef86c5fe319536a999246a49c3406bc (patch) | |
tree | 3e14246e64adff903d18ffdccd4030071eed9c47 /src | |
parent | 504770250595fdb8f3f56400ea101a4d0d45faff (diff) | |
download | hercules-3ce598dc1ef86c5fe319536a999246a49c3406bc.tar.gz hercules-3ce598dc1ef86c5fe319536a999246a49c3406bc.tar.bz2 hercules-3ce598dc1ef86c5fe319536a999246a49c3406bc.tar.xz hercules-3ce598dc1ef86c5fe319536a999246a49c3406bc.zip |
Added const qualifier to some typecasts
Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/char/int_guild.c | 18 | ||||
-rw-r--r-- | src/common/md5calc.c | 6 | ||||
-rw-r--r-- | src/map/atcommand.c | 28 | ||||
-rw-r--r-- | src/map/intif.c | 4 | ||||
-rw-r--r-- | src/map/script.c | 85 | ||||
-rw-r--r-- | src/map/storage.c | 4 | ||||
-rw-r--r-- | src/map/vending.c | 6 |
7 files changed, 76 insertions, 75 deletions
diff --git a/src/char/int_guild.c b/src/char/int_guild.c index 2ba50d277..c637f12fd 100644 --- a/src/char/int_guild.c +++ b/src/char/int_guild.c @@ -1547,17 +1547,17 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int switch(type) { case GMI_POSITION: - { - g->member[i].position=*((const short *)data); + { + g->member[i].position = *(const short *)data; g->member[i].modified = GS_MEMBER_MODIFIED; mapif->guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; break; - } + } case GMI_EXP: { uint64 old_exp = g->member[i].exp; - g->member[i].exp=*((const uint64 *)data); + g->member[i].exp = *(const uint64 *)data; g->member[i].modified = GS_MEMBER_MODIFIED; if (g->member[i].exp > old_exp) { uint64 exp = g->member[i].exp - old_exp; @@ -1582,7 +1582,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int } case GMI_HAIR: { - g->member[i].hair=*((const short *)data); + g->member[i].hair = *(const short *)data; g->member[i].modified = GS_MEMBER_MODIFIED; mapif->guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. @@ -1590,7 +1590,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int } case GMI_HAIR_COLOR: { - g->member[i].hair_color=*((const short *)data); + g->member[i].hair_color = *(const short *)data; g->member[i].modified = GS_MEMBER_MODIFIED; mapif->guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. @@ -1598,7 +1598,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int } case GMI_GENDER: { - g->member[i].gender=*((const short *)data); + g->member[i].gender = *(const short *)data; g->member[i].modified = GS_MEMBER_MODIFIED; mapif->guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. @@ -1606,7 +1606,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int } case GMI_CLASS: { - g->member[i].class_=*((const short *)data); + g->member[i].class_ = *(const short *)data; g->member[i].modified = GS_MEMBER_MODIFIED; mapif->guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. @@ -1614,7 +1614,7 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int } case GMI_LEVEL: { - g->member[i].lv=*((const short *)data); + g->member[i].lv = *(const short *)data; g->member[i].modified = GS_MEMBER_MODIFIED; mapif->guild_memberinfochanged(guild_id,account_id,char_id,type,data,len); g->save_flag |= GS_MEMBER; //Save new data. diff --git a/src/common/md5calc.c b/src/common/md5calc.c index bc70d9006..d346c8aa4 100644 --- a/src/common/md5calc.c +++ b/src/common/md5calc.c @@ -169,7 +169,7 @@ static void MD5_String2binary(const char * string, unsigned char * output) //var /*8bit*/ unsigned char padding_message[64]; //Extended message 512bit 64byte - const unsigned char *pstring; //The position of string in the present scanning notes is held. + const unsigned char *pstring; // The position of string in the present scanning notes is held. /*32bit*/ unsigned int string_byte_len, //The byte chief of string is held. @@ -192,7 +192,7 @@ static void MD5_String2binary(const char * string, unsigned char * output) //Step 1.Append Padding Bits (extension of a mark bit) //1-1 string_byte_len = (unsigned int)strlen(string); //The byte chief of a character sequence is acquired. - pstring = (const unsigned char *)string; //The position of the present character sequence is set. + pstring = (const unsigned char *)string; // The position of the present character sequence is set. //1-2 Repeat calculation until length becomes less than 64 bytes. for (i=string_byte_len; 64<=i; i-=64,pstring+=64) @@ -200,7 +200,7 @@ static void MD5_String2binary(const char * string, unsigned char * output) //1-3 copy_len = string_byte_len % 64; //The number of bytes which remained is computed. - strncpy((char *)padding_message, (const char *)pstring, copy_len); //A message is copied to an extended bit sequence. + strncpy((char *)padding_message, (const char *)pstring, copy_len); // A message is copied to an extended bit sequence. memset(padding_message+copy_len, 0, 64 - copy_len); //It buries by 0 until it becomes extended bit length. padding_message[copy_len] |= 0x80; //The next of a message is 1. diff --git a/src/map/atcommand.c b/src/map/atcommand.c index e422a5de4..963f5c970 100644 --- a/src/map/atcommand.c +++ b/src/map/atcommand.c @@ -547,7 +547,7 @@ ACMD(jumpto) { return false; } - if((pl_sd=map->nick2sd((const char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -2747,7 +2747,7 @@ ACMD(recall) { return false; } - if((pl_sd=map->nick2sd((const char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -3072,7 +3072,7 @@ ACMD(kick) return false; } - if((pl_sd=map->nick2sd((const char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -5125,8 +5125,7 @@ ACMD(follow) { return true; } - if ((pl_sd = map->nick2sd((const char *)message)) == NULL) - { + if ((pl_sd = map->nick2sd(message)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -5603,7 +5602,7 @@ ACMD(changegm) { return false; } - if ((pl_sd=map->nick2sd((const char *) message)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) { + if ((pl_sd=map->nick2sd(message)) == NULL || pl_sd->status.guild_id != sd->status.guild_id) { clif->message(fd, msg_fd(fd,1184)); // Target character must be online and be a guild member. return false; } @@ -5623,7 +5622,7 @@ ACMD(changeleader) { return false; } - if (party->changeleader(sd, map->nick2sd((const char *) message))) + if (party->changeleader(sd, map->nick2sd(message))) return true; return false; } @@ -6382,7 +6381,7 @@ ACMD(trade) { return false; } - if ( (pl_sd = map->nick2sd((const char *)message)) == NULL ) { + if ((pl_sd = map->nick2sd(message)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -6425,8 +6424,7 @@ ACMD(unmute) { return false; } - if ((pl_sd = map->nick2sd((const char *)message)) == NULL) - { + if ((pl_sd = map->nick2sd(message)) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } @@ -7667,9 +7665,10 @@ ACMD(showdelay) * @reject - reject invitation * @leave - leave duel *------------------------------------------*/ -ACMD(invite) { +ACMD(invite) +{ unsigned int did = sd->duel_group; - struct map_session_data *target_sd = map->nick2sd((const char *)message); + struct map_session_data *target_sd = map->nick2sd(message); if (did == 0) { @@ -7741,8 +7740,7 @@ ACMD(duel) { } duel->create(sd, maxpl); } else { - struct map_session_data *target_sd; - target_sd = map->nick2sd((const char *)message); + struct map_session_data *target_sd = map->nick2sd(message); if (target_sd != NULL) { unsigned int newduel; if ((newduel = duel->create(sd, 2)) != -1) { @@ -7884,7 +7882,7 @@ ACMD(clone) { return false; } - if ((pl_sd=map->nick2sd((const char *)message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { + if ((pl_sd=map->nick2sd(message)) == NULL && (pl_sd=map->charid2sd(atoi(message))) == NULL) { clif->message(fd, msg_fd(fd,3)); // Character not found. return false; } diff --git a/src/map/intif.c b/src/map/intif.c index 7d2493d46..4b3e913e1 100644 --- a/src/map/intif.c +++ b/src/map/intif.c @@ -1110,7 +1110,7 @@ void intif_parse_Registers(int fd) safestrncpy(sval, RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len)); cursor += len + 1; - script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, (void*)sval, NULL); + script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, sval, NULL); } /** * Vessel! @@ -1132,7 +1132,7 @@ void intif_parse_Registers(int fd) ival = RFIFOL(fd, cursor); cursor += 4; - script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, (void*)h64BPTRSIZE(ival), NULL); + script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, (const void *)h64BPTRSIZE(ival), NULL); } } script->parser_current_file = NULL;/* reset */ diff --git a/src/map/script.c b/src/map/script.c index fd653523d..c054d3bc4 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -6386,16 +6386,13 @@ BUILDIN(input) } else { // take received text/value and store it in the designated variable sd->state.menu_or_input = 0; - if( is_string_variable(name) ) - { + if (is_string_variable(name)) { int len = (int)strlen(sd->npc_str); - script->set_reg(st, sd, uid, name, (void*)sd->npc_str, script_getref(st,2)); + script->set_reg(st, sd, uid, name, sd->npc_str, script_getref(st,2)); script_pushint(st, (len > max ? 1 : len < min ? -1 : 0)); - } - else - { + } else { int amount = sd->npc_amount; - script->set_reg(st, sd, uid, name, (void*)h64BPTRSIZE(cap_value(amount,min,max)), script_getref(st,2)); + script->set_reg(st, sd, uid, name, (const void *)h64BPTRSIZE(cap_value(amount,min,max)), script_getref(st,2)); script_pushint(st, (amount > max ? 1 : amount < min ? -1 : 0)); } st->state = RUN; @@ -6482,9 +6479,9 @@ BUILDIN(__setr) } if (is_string_variable(name)) - script->set_reg(st,sd,num,name,(void*)script_getstr(st,3),script_getref(st,2)); + script->set_reg(st, sd, num, name, script_getstr(st, 3), script_getref(st, 2)); else - script->set_reg(st,sd,num,name,(void*)h64BPTRSIZE(script_getnum(st,3)),script_getref(st,2)); + script->set_reg(st, sd, num, name, (const void *)h64BPTRSIZE(script_getnum(st, 3)), script_getref(st, 2)); return true; } @@ -6531,15 +6528,14 @@ BUILDIN(setarray) if( end > SCRIPT_MAX_ARRAYSIZE ) end = SCRIPT_MAX_ARRAYSIZE; - if( is_string_variable(name) ) - {// string array - for( i = 3; start < end; ++start, ++i ) - script->set_reg(st, sd, reference_uid(id, start), name, (void*)script_getstr(st,i), reference_getref(data)); - } - else - {// int array - for( i = 3; start < end; ++start, ++i ) - script->set_reg(st, sd, reference_uid(id, start), name, (void*)h64BPTRSIZE(script_getnum(st,i)), reference_getref(data)); + if (is_string_variable(name)) { + // string array + for (i = 3; start < end; ++start, ++i) + script->set_reg(st, sd, reference_uid(id, start), name, script_getstr(st, i), reference_getref(data)); + } else { + // int array + for (i = 3; start < end; ++start, ++i) + script->set_reg(st, sd, reference_uid(id, start), name, (const void *)h64BPTRSIZE(script_getnum(st, i)), reference_getref(data)); } return true; } @@ -6555,7 +6551,7 @@ BUILDIN(cleararray) uint32 start; uint32 end; int32 id; - void* v; + const void *v = NULL; struct map_session_data *sd = NULL; data = script_getdata(st, 2); @@ -6578,10 +6574,10 @@ BUILDIN(cleararray) return true;// no player attached } - if( is_string_variable(name) ) - v = (void*)script_getstr(st, 3); + if (is_string_variable(name)) + v = script_getstr(st, 3); else - v = (void*)h64BPTRSIZE(script_getnum(st, 3)); + v = (const void *)h64BPTRSIZE(script_getnum(st, 3)); end = start + script_getnum(st, 4); if( end > SCRIPT_MAX_ARRAYSIZE ) @@ -6667,7 +6663,12 @@ BUILDIN(copyarray) script_removetop(st, -1, 0); } else { // out of range - assume ""/0 - script->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, (is_string_variable(name1)?(void*)"":(void*)0), reference_getref(data1)); + const void *value; + if (is_string_variable(name1)) + value = ""; + else + value = (const void *)0; + script->set_reg(st, sd, reference_uid(id1, idx1 + i), name1, value, reference_getref(data1)); } } } @@ -6696,8 +6697,9 @@ BUILDIN(getarraysize) script_pushint(st, script->array_highest_key(st,st->rid ? script->rid2sd(st) : NULL,reference_getname(data),reference_getref(data))); return true; } -int script_array_index_cmp(const void *a, const void *b) { - return ( *(const unsigned int*)a - *(const unsigned int*)b ); +int script_array_index_cmp(const void *a, const void *b) +{ + return (*(const unsigned int *)a - *(const unsigned int *)b); // FIXME: Is the unsigned difference really intended here? } /// Deletes count or all the elements in an array, from the starting index. @@ -11054,9 +11056,9 @@ BUILDIN(getstatus) case 4: script_pushint(st, sd->sc.data[id]->val4); break; case 5: { - const struct TimerData* td = (const struct TimerData*)timer->get(sd->sc.data[id]->timer); + const struct TimerData *td = timer->get(sd->sc.data[id]->timer); - if( td ) { + if (td != NULL) { // return the amount of time remaining script_pushint(st, (int)(td->tick - timer->gettick())); // TODO: change this to int64 when we'll support 64 bit script values } @@ -14407,7 +14409,7 @@ BUILDIN(getmapxy) sd=script->rid2sd(st); else sd=NULL; - script->set_reg(st,sd,num,name,(void*)mapname,script_getref(st,2)); + script->set_reg(st, sd, num, name, mapname, script_getref(st, 2)); //Set MapX num=st->stack->stack_data[st->start+3].u.num; @@ -14418,7 +14420,7 @@ BUILDIN(getmapxy) sd=script->rid2sd(st); else sd=NULL; - script->set_reg(st,sd,num,name,(void*)h64BPTRSIZE(x),script_getref(st,3)); + script->set_reg(st, sd, num, name, (const void *)h64BPTRSIZE(x), script_getref(st, 3)); //Set MapY num=st->stack->stack_data[st->start+4].u.num; @@ -14429,7 +14431,7 @@ BUILDIN(getmapxy) sd=script->rid2sd(st); else sd=NULL; - script->set_reg(st,sd,num,name,(void*)h64BPTRSIZE(y),script_getref(st,4)); + script->set_reg(st, sd, num, name, (const void *)h64BPTRSIZE(y), script_getref(st, 4)); //Return Success value script_pushint(st,0); @@ -15089,7 +15091,7 @@ BUILDIN(explode) if (str[i] == delimiter && (int64)start + k < (int64)(SCRIPT_MAX_ARRAYSIZE-1)) { // FIXME[Haru]: SCRIPT_MAX_ARRAYSIZE should really be unsigned (and INT32_MAX) //break at delimiter but ignore after reaching last array index temp[j] = '\0'; - script->set_reg(st, sd, reference_uid(id, start + k), name, (void*)temp, reference_getref(data)); + script->set_reg(st, sd, reference_uid(id, start + k), name, temp, reference_getref(data)); k++; j = 0; } else { @@ -15098,7 +15100,7 @@ BUILDIN(explode) } //set last string temp[j] = '\0'; - script->set_reg(st, sd, reference_uid(id, start + k), name, (void*)temp, reference_getref(data)); + script->set_reg(st, sd, reference_uid(id, start + k), name, temp, reference_getref(data)); aFree(temp); @@ -15418,12 +15420,12 @@ BUILDIN(sscanf) { if(sscanf(str, buf, ref_str)==0) { break; } - script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)(ref_str), reference_getref(data)); + script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, ref_str, reference_getref(data)); } else { // Number if(sscanf(str, buf, &ref_int)==0) { break; } - script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (void *)h64BPTRSIZE(ref_int), reference_getref(data)); + script->set_reg(st, sd, reference_uid( reference_getid(data), reference_getindex(data) ), buf_p, (const void *)h64BPTRSIZE(ref_int), reference_getref(data)); } arg++; @@ -15863,8 +15865,8 @@ BUILDIN(swap) value2 = script_getstr(st,3); if (strcmpi(value1, value2)) { - script->set_reg(st, sd, uid1, varname1, (void*)(value2), script_getref(st,3)); - script->set_reg(st, sd, uid2, varname2, (void*)(value1), script_getref(st,2)); + script->set_reg(st, sd, uid1, varname1, value2, script_getref(st,3)); + script->set_reg(st, sd, uid2, varname2, value1, script_getref(st,2)); } } else { @@ -15874,8 +15876,8 @@ BUILDIN(swap) value2 = script_getnum(st,3); if (value1 != value2) { - script->set_reg(st, sd, uid1, varname1, (void*)h64BPTRSIZE(value2), script_getref(st,3)); - script->set_reg(st, sd, uid2, varname2, (void*)h64BPTRSIZE(value1), script_getref(st,2)); + script->set_reg(st, sd, uid1, varname1, (const void *)h64BPTRSIZE(value2), script_getref(st,3)); + script->set_reg(st, sd, uid2, varname2, (const void *)h64BPTRSIZE(value1), script_getref(st,2)); } } return true; @@ -16529,7 +16531,7 @@ BUILDIN(searchitem) for( i = 0; i < count; ++start, ++i ) {// Set array - void* v = (void*)h64BPTRSIZE((int)items[i]->nameid); + const void *v = (const void *)h64BPTRSIZE((int)items[i]->nameid); script->set_reg(st, sd, reference_uid(id, start), name, v, reference_getref(data)); } @@ -19743,9 +19745,10 @@ BUILDIN(checkbound) /* bg_match_over( arena_name {, optional canceled } ) */ /* returns 0 when successful, 1 otherwise */ -BUILDIN(bg_match_over) { +BUILDIN(bg_match_over) +{ bool canceled = script_hasdata(st,3) ? true : false; - struct bg_arena *arena = bg->name2arena((const char*)script_getstr(st, 2)); + struct bg_arena *arena = bg->name2arena(script_getstr(st, 2)); if( arena ) { bg->match_over(arena,canceled); diff --git a/src/map/storage.c b/src/map/storage.c index ceac85916..b8ec1e31e 100644 --- a/src/map/storage.c +++ b/src/map/storage.c @@ -52,8 +52,8 @@ struct guild_storage_interface *gstorage; *------------------------------------------*/ int storage_comp_item(const void *i1_, const void *i2_) { - const struct item *i1 = (const struct item *)i1_; - const struct item *i2 = (const struct item *)i2_; + const struct item *i1 = i1_; + const struct item *i2 = i2_; if (i1->nameid == i2->nameid) return 0; diff --git a/src/map/vending.c b/src/map/vending.c index 2346932ba..d9001f6f5 100644 --- a/src/map/vending.c +++ b/src/map/vending.c @@ -118,7 +118,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid, // some checks z = 0; // zeny counter w = 0; // weight counter - for( i = 0; i < count; i++ ) { + for (i = 0; i < count; i++) { short amount = *(const uint16*)(data + 4*i + 0); short idx = *(const uint16*)(data + 4*i + 2); idx -= 2; @@ -184,7 +184,7 @@ void vending_purchasereq(struct map_session_data* sd, int aid, unsigned int uid, z -= apply_percentrate64(z, battle_config.vending_tax, 10000); pc->getzeny(vsd, (int)z, LOG_TYPE_VENDING, sd); - for( i = 0; i < count; i++ ) { + for (i = 0; i < count; i++) { short amount = *(const uint16*)(data + 4*i + 0); short idx = *(const uint16*)(data + 4*i + 2); idx -= 2; @@ -265,7 +265,7 @@ void vending_openvending(struct map_session_data* sd, const char* message, const // filter out invalid items i = 0; - for( j = 0; j < count; j++ ) { + for (j = 0; j < count; j++) { short index = *(const uint16*)(data + 8*j + 0); short amount = *(const uint16*)(data + 8*j + 2); unsigned int value = *(const uint32*)(data + 8*j + 4); |