summaryrefslogtreecommitdiff
path: root/src/char
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2015-01-20 04:36:08 +0100
committerHaru <haru@dotalux.com>2015-01-20 04:41:33 +0100
commit4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4 (patch)
treedab9d12a6a4b95a37598e27e6e86d6047360d61b /src/char
parent03709c136ad300be631adfd38dc36c2433bda718 (diff)
downloadhercules-4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4.tar.gz
hercules-4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4.tar.bz2
hercules-4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4.tar.xz
hercules-4ae2b9b72dd4fce3d7a7778222d1c39abbb564a4.zip
Minor fixes and tweaks suggested by cppcheck
- Variable scopes reduced - Parenthesized ambiguous expressions - Removed or added NULL checks where (un)necessary - Corrected format strings - Fixed typos potentially leading to bugs Signed-off-by: Haru <haru@dotalux.com>
Diffstat (limited to 'src/char')
-rw-r--r--src/char/char.c49
-rw-r--r--src/char/geoip.c3
-rw-r--r--src/char/int_auction.c5
-rw-r--r--src/char/int_guild.c13
-rw-r--r--src/char/int_homun.c18
-rw-r--r--src/char/int_mail.c2
-rw-r--r--src/char/int_party.c12
-rw-r--r--src/char/int_storage.c11
-rw-r--r--src/char/inter.c5
-rw-r--r--src/char/pincode.c5
10 files changed, 54 insertions, 69 deletions
diff --git a/src/char/char.c b/src/char/char.c
index 1301f2cc4..e43ebbfbc 100644
--- a/src/char/char.c
+++ b/src/char/char.c
@@ -1961,7 +1961,7 @@ int char_mmo_char_tobuf(uint8* buffer, struct mmo_charstatus* p) {
#endif
//When the weapon is sent and your option is riding, the client crashes on login!?
- WBUFW(buf,56) = p->option&(0x20|0x80000|0x100000|0x200000|0x400000|0x800000|0x1000000|0x2000000|0x4000000|0x8000000) ? 0 : p->weapon;
+ WBUFW(buf,56) = (p->option&(0x20|0x80000|0x100000|0x200000|0x400000|0x800000|0x1000000|0x2000000|0x4000000|0x8000000)) ? 0 : p->weapon;
WBUFW(buf,58) = p->base_level;
WBUFW(buf,60) = min(p->skill_point, INT16_MAX);
@@ -2988,12 +2988,12 @@ void char_map_received_ok(int fd)
void char_send_maps(int fd, int id, int j)
{
- unsigned char buf[16384];
- int x,i;
+ int k,i;
if (j == 0) {
ShowWarning("Map-server %d has NO maps.\n", id);
} else {
+ unsigned char buf[16384];
// Transmitting maps information to the other map-servers
WBUFW(buf,0) = 0x2b04;
WBUFW(buf,2) = j * 4 + 10;
@@ -3003,16 +3003,16 @@ void char_send_maps(int fd, int id, int j)
mapif->sendallwos(fd, buf, WBUFW(buf,2));
}
// Transmitting the maps of the other map-servers to the new map-server
- for(x = 0; x < ARRAYLENGTH(chr->server); x++) {
- if (chr->server[x].fd > 0 && x != id) {
- WFIFOHEAD(fd,10 +4*chr->server[x].maps);
+ for(k = 0; k < ARRAYLENGTH(chr->server); k++) {
+ if (chr->server[k].fd > 0 && k != id) {
+ WFIFOHEAD(fd,10 +4*chr->server[k].maps);
WFIFOW(fd,0) = 0x2b04;
- WFIFOL(fd,4) = htonl(chr->server[x].ip);
- WFIFOW(fd,8) = htons(chr->server[x].port);
+ WFIFOL(fd,4) = htonl(chr->server[k].ip);
+ WFIFOW(fd,8) = htons(chr->server[k].port);
j = 0;
- for(i = 0; i < chr->server[x].maps; i++)
- if (chr->server[x].map[i])
- WFIFOW(fd,10+(j++)*4) = chr->server[x].map[i];
+ for(i = 0; i < chr->server[k].maps; i++)
+ if (chr->server[k].map[i])
+ WFIFOW(fd,10+(j++)*4) = chr->server[k].map[i];
if (j > 0) {
WFIFOW(fd,2) = j * 4 + 10;
WFIFOSET(fd,WFIFOW(fd,2));
@@ -3123,17 +3123,15 @@ void char_parse_frommap_set_users_count(int fd, int id)
void char_parse_frommap_set_users(int fd, int id)
{
//TODO: When data mismatches memory, update guild/party online/offline states.
- int aid, cid, i;
- struct online_char_data* character;
+ int i;
chr->server[id].users = RFIFOW(fd,4);
chr->online_char_db->foreach(chr->online_char_db,chr->db_setoffline,id); //Set all chars from this server as 'unknown'
for(i = 0; i < chr->server[id].users; i++) {
- aid = RFIFOL(fd,6+i*8);
- cid = RFIFOL(fd,6+i*8+4);
- character = idb_ensure(chr->online_char_db, aid, chr->create_online_char_data);
- if( character->server > -1 && character->server != id )
- {
+ int aid = RFIFOL(fd,6+i*8);
+ int cid = RFIFOL(fd,6+i*8+4);
+ struct online_char_data *character = idb_ensure(chr->online_char_db, aid, chr->create_online_char_data);
+ if (character->server > -1 && character->server != id) {
ShowNotice("Set map user: Character (%d:%d) marked on map server %d, but map server %d claims to have (%d:%d) online!\n",
character->account_id, character->char_id, character->server, id, aid, cid);
mapif->disconnectplayer(chr->server[character->server].fd, character->account_id, character->char_id, 2);
@@ -4153,7 +4151,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, party_id, guild_id, i;
+ int char_id, i;
char* data;
time_t delete_date;
@@ -4183,12 +4181,11 @@ static void char_delete2_req(int fd, struct char_session_data* sd)
// This check is imposed by Aegis to avoid dead entries in databases
// _it is not needed_ as we clear data properly
// see issue: 7338
- if( char_aegis_delete )
- {
+ if (char_aegis_delete) {
+ int party_id = 0, guild_id = 0;
if( SQL_SUCCESS != SQL->Query(inter->sql_handle, "SELECT `party_id`, `guild_id` FROM `%s` WHERE `char_id`='%d'", char_db, char_id)
- || SQL_SUCCESS != SQL->NextRow(inter->sql_handle)
- )
- {
+ || SQL_SUCCESS != SQL->NextRow(inter->sql_handle)
+ ) {
Sql_ShowDebug(inter->sql_handle);
chr->delete2_ack(fd, char_id, 3, 0);
return;
@@ -5585,12 +5582,12 @@ int char_config_read(const char* cfgName)
start_point.y = y;
} else if (strcmpi(w1, "start_items") == 0) {
int i;
- char *split, *split2;
+ char *split;
i = 0;
split = strtok(w2, ",");
while (split != NULL && i < MAX_START_ITEMS*3) {
- split2 = split;
+ char *split2 = split;
split = strtok(NULL, ",");
start_items[i] = atoi(split2);
diff --git a/src/char/geoip.c b/src/char/geoip.c
index e5b77af1f..1268019e1 100644
--- a/src/char/geoip.c
+++ b/src/char/geoip.c
@@ -56,14 +56,13 @@ const char* geoip_getcountry(uint32 ipnum)
{
int depth;
unsigned int x;
- const unsigned char *buf;
unsigned int offset = 0;
if( geoip->data->active == false )
return geoip_countryname[0];
for (depth = 31; depth >= 0; depth--) {
- buf = geoip->data->cache + (long)6 *offset;
+ const unsigned char *buf = geoip->data->cache + (long)6 *offset;
if (ipnum & (1 << depth)) {
/* Take the right-hand branch */
x = (buf[3*1 + 0] << (0*8))
diff --git a/src/char/int_auction.c b/src/char/int_auction.c
index 5d42e6398..164ca5360 100644
--- a/src/char/int_auction.c
+++ b/src/char/int_auction.c
@@ -175,7 +175,6 @@ void inter_auctions_fromsql(void)
{
int i;
struct auction_data *auction;
- struct item *item;
char *data;
StringBuf buf;
int64 tick = timer->gettick(), endtick;
@@ -193,8 +192,8 @@ void inter_auctions_fromsql(void)
StrBuf->Destroy(&buf);
- while( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) )
- {
+ while (SQL_SUCCESS == SQL->NextRow(inter->sql_handle)) {
+ struct item *item;
CREATE(auction, struct auction_data, 1);
SQL->GetData(inter->sql_handle, 0, &data, NULL); auction->auction_id = atoi(data);
SQL->GetData(inter->sql_handle, 1, &data, NULL); auction->seller_id = atoi(data);
diff --git a/src/char/int_guild.c b/src/char/int_guild.c
index 7af01f883..20db452af 100644
--- a/src/char/int_guild.c
+++ b/src/char/int_guild.c
@@ -220,14 +220,12 @@ int inter_guild_tosql(struct guild *g,int flag)
StrBuf->Destroy(&buf);
}
- if (flag&GS_MEMBER)
- {
- struct guild_member *m;
+ if (flag&GS_MEMBER) {
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) {
@@ -1509,12 +1507,11 @@ int mapif_parse_GuildMemberInfoChange(int fd, int guild_id, int account_id, int
}
case GMI_EXP:
{
- uint64 exp, old_exp=g->member[i].exp;
+ uint64 old_exp = g->member[i].exp;
g->member[i].exp=*((uint64 *)data);
g->member[i].modified = GS_MEMBER_MODIFIED;
- if (g->member[i].exp > old_exp)
- {
- exp = g->member[i].exp - old_exp;
+ if (g->member[i].exp > old_exp) {
+ uint64 exp = g->member[i].exp - old_exp;
// Compute gained exp
if (guild_exp_rate != 100)
diff --git a/src/char/int_homun.c b/src/char/int_homun.c
index 7f9323bdd..dd23261c2 100644
--- a/src/char/int_homun.c
+++ b/src/char/int_homun.c
@@ -155,7 +155,6 @@ bool mapif_homunculus_save(struct s_homunculus* hd)
// Load an homunculus
bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
{
- int i;
char* data;
size_t len;
@@ -207,24 +206,23 @@ bool mapif_homunculus_load(int homun_id, struct s_homunculus* hd)
hd->hunger = cap_value(hd->hunger, 0, 100);
// Load Homunculus Skill
- if( SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `homun_id`=%d", skill_homunculus_db, homun_id) )
- {
+ if (SQL_ERROR == SQL->Query(inter->sql_handle, "SELECT `id`,`lv` FROM `%s` WHERE `homun_id`=%d", skill_homunculus_db, homun_id)) {
Sql_ShowDebug(inter->sql_handle);
return false;
}
- while( SQL_SUCCESS == SQL->NextRow(inter->sql_handle) )
- {
+ while (SQL_SUCCESS == SQL->NextRow(inter->sql_handle)) {
+ int idx;
// id
SQL->GetData(inter->sql_handle, 0, &data, NULL);
- i = atoi(data);
- if( i < HM_SKILLBASE || i >= HM_SKILLBASE + MAX_HOMUNSKILL )
+ idx = atoi(data);
+ if (idx < HM_SKILLBASE || idx >= HM_SKILLBASE + MAX_HOMUNSKILL)
continue;// invalid skill id
- i = i - HM_SKILLBASE;
- hd->hskill[i].id = (unsigned short)atoi(data);
+ idx -= HM_SKILLBASE;
+ hd->hskill[idx].id = (unsigned short)atoi(data);
// lv
SQL->GetData(inter->sql_handle, 1, &data, NULL);
- hd->hskill[i].lv = (unsigned char)atoi(data);
+ hd->hskill[idx].lv = (unsigned char)atoi(data);
}
SQL->FreeResult(inter->sql_handle);
diff --git a/src/char/int_mail.c b/src/char/int_mail.c
index 0e5043e14..79d20cbd1 100644
--- a/src/char/int_mail.c
+++ b/src/char/int_mail.c
@@ -27,7 +27,6 @@ static int inter_mail_fromsql(int char_id, struct mail_data* md)
{
int i, j;
struct mail_message *msg;
- struct item *item;
char *data;
StringBuf buf;
@@ -53,6 +52,7 @@ static int inter_mail_fromsql(int char_id, struct mail_data* md)
for (i = 0; i < MAIL_MAX_INBOX && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++i )
{
msg = &md->msg[i];
+ struct item *item;
SQL->GetData(inter->sql_handle, 0, &data, NULL); msg->id = atoi(data);
SQL->GetData(inter->sql_handle, 1, &data, NULL); safestrncpy(msg->send_name, data, NAME_LENGTH);
SQL->GetData(inter->sql_handle, 2, &data, NULL); msg->send_id = atoi(data);
diff --git a/src/char/int_party.c b/src/char/int_party.c
index b16f106be..bf950ec42 100644
--- a/src/char/int_party.c
+++ b/src/char/int_party.c
@@ -54,7 +54,6 @@ static int inter_party_check_lv(struct party_data *p) {
static void inter_party_calc_state(struct party_data *p)
{
int i;
- unsigned int lv;
p->min_lv = UINT_MAX;
p->max_lv = 0;
p->party.count =
@@ -83,13 +82,12 @@ static void inter_party_calc_state(struct party_data *p)
);
}
//max/min levels.
- for(i=0;i<MAX_PARTY;i++){
- lv=p->party.member[i].lv;
+ for (i = 0; i < MAX_PARTY; i++) {
+ unsigned int lv = p->party.member[i].lv;
if (!lv) continue;
- if(p->party.member[i].online &&
- //On families, the kid is not counted towards exp share rules.
- p->party.member[i].char_id != p->family)
- {
+ if (p->party.member[i].online
+ && p->party.member[i].char_id != p->family /* In families, the kid is not counted towards exp share rules. */
+ ) {
if( lv < p->min_lv ) p->min_lv=lv;
if( p->max_lv < lv ) p->max_lv=lv;
}
diff --git a/src/char/int_storage.c b/src/char/int_storage.c
index f2dd4d47a..db49eb46e 100644
--- a/src/char/int_storage.c
+++ b/src/char/int_storage.c
@@ -36,7 +36,6 @@ int inter_storage_tosql(int account_id, struct storage_data* p)
int inter_storage_fromsql(int account_id, struct storage_data* p)
{
StringBuf buf;
- struct item* item;
char* data;
int i;
int j;
@@ -56,9 +55,8 @@ int inter_storage_fromsql(int account_id, struct storage_data* p)
StrBuf->Destroy(&buf);
- for( i = 0; i < MAX_STORAGE && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++i )
- {
- item = &p->items[i];
+ for (i = 0; i < MAX_STORAGE && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++i) {
+ struct item *item = &p->items[i];
SQL->GetData(inter->sql_handle, 0, &data, NULL); item->id = atoi(data);
SQL->GetData(inter->sql_handle, 1, &data, NULL); item->nameid = atoi(data);
SQL->GetData(inter->sql_handle, 2, &data, NULL); item->amount = atoi(data);
@@ -93,7 +91,6 @@ int inter_storage_guild_storage_tosql(int guild_id, struct guild_storage* p)
int inter_storage_guild_storage_fromsql(int guild_id, struct guild_storage* p)
{
StringBuf buf;
- struct item* item;
char* data;
int i;
int j;
@@ -114,8 +111,8 @@ int inter_storage_guild_storage_fromsql(int guild_id, struct guild_storage* p)
StrBuf->Destroy(&buf);
- for( i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++i ) {
- item = &p->items[i];
+ for (i = 0; i < MAX_GUILD_STORAGE && SQL_SUCCESS == SQL->NextRow(inter->sql_handle); ++i) {
+ struct item *item = &p->items[i];
SQL->GetData(inter->sql_handle, 0, &data, NULL); item->id = atoi(data);
SQL->GetData(inter->sql_handle, 1, &data, NULL); item->nameid = atoi(data);
SQL->GetData(inter->sql_handle, 2, &data, NULL); item->amount = atoi(data);
diff --git a/src/char/inter.c b/src/char/inter.c
index 6cd34dc39..5af9a6aab 100644
--- a/src/char/inter.c
+++ b/src/char/inter.c
@@ -764,7 +764,6 @@ int inter_accreg_fromsql(int account_id,int char_id, int fd, int type)
*------------------------------------------*/
static int inter_config_read(const char* cfgName)
{
- int i;
char line[1024], w1[1024], w2[1024];
FILE* fp;
@@ -775,7 +774,7 @@ static int inter_config_read(const char* cfgName)
}
while (fgets(line, sizeof(line), fp)) {
- i = sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2);
+ int i = sscanf(line, "%1023[^:]: %1023[^\r\n]", w1, w2);
if(i != 2)
continue;
@@ -1149,13 +1148,13 @@ int mapif_parse_Registry(int fd)
if( count ) {
int cursor = 14, i;
char key[32], sval[254];
- unsigned int index;
bool isLoginActive = session_isActive(chr->login_fd);
if( isLoginActive )
chr->global_accreg_to_login_start(account_id,char_id);
for(i = 0; i < count; i++) {
+ unsigned int index;
safestrncpy(key, (char*)RFIFOP(fd, cursor + 1), RFIFOB(fd, cursor));
cursor += RFIFOB(fd, cursor) + 1;
diff --git a/src/char/pincode.c b/src/char/pincode.c
index 325a705a5..b8b30a1b8 100644
--- a/src/char/pincode.c
+++ b/src/char/pincode.c
@@ -126,10 +126,11 @@ void pincode_notifyLoginPinError(int account_id) {
}
void pincode_decrypt(unsigned int userSeed, char* pin) {
- int i, pos;
+ int i;
char tab[10] = {0,1,2,3,4,5,6,7,8,9};
- for( i = 1; i < 10; i++ ){
+ for (i = 1; i < 10; i++) {
+ int pos;
userSeed = pincode->baseSeed + userSeed * pincode->multiplier;
pos = userSeed % (i + 1);
if( i != pos ){