21 Jan, 2007, gazzy123 wrote in the 1st comment:
Votes: 0
"comparison between signed and unsigned integer expressions"

I get theese alot when compiling is there a real problem? in that case how to fix them? doing (unsigned) before the variables?
21 Jan, 2007, Keberus wrote in the 2nd comment:
Votes: 0
You might as well fix it….its pretty easy just use typecasting. I see these a lot when comparing an int to a strlen() value. So lets set it up real fast.
char *string;
int value1;

if( value1 < strlen(string) )


That errors….to fix typecast integer to strlen(string) it would like something like this.
char *string;
int value1;

if( value1 < (int)(strlen(string)) )


Pretty easy for stuff like that.

Later,
KeB
21 Jan, 2007, Omega wrote in the 3rd comment:
Votes: 0
you can avoid this by using a compiler flag .. i believe its like, -fno_unsigned or something..

look at the manpages under 'man gcc' for a list of possible compiler flags, look for ones relating to comparison and signed/unsigned, there will be one that you can use to disable this warning.
21 Jan, 2007, Guest wrote in the 4th comment:
Votes: 0
I prefer to fix these more generally. Using Keberus' example code you can fix it like so:

char *string;
int value1;

if( value1 < strlen(string) )


That errors….to fix typecast integer to strlen(string) it would like something like this.
char *string;
size_t value1;

if( value1 < (strlen(string)) )


size_t is a special identifier that tells the compiler to use whatever the system specific type is for certain things. Most library functions accept size_t as an argument type, and will return size_t type values. Generally size_t will be typed to an unsigned integer which is why the above code would complain since value1 was originally defined as an integer.

It's good practice to avoid casting unless you have no other choice.

If you run across any specific examples you need help with, go ahead and post them here. It's probably the same idea though.
21 Jan, 2007, gazzy123 wrote in the 5th comment:
Votes: 0
So I can use size_t for any types? now I got illegal conversions from char const to char aswell.
holy shit, this is alot of work :)
21 Jan, 2007, Guest wrote in the 6th comment:
Votes: 0
I woudln't go throwing it around needlessly. Only when you get specific complaints like comparing unsigned with signed. That's usually your indicator that it needs to be done.

Illegal conversions from char const* to char* are a whole other breed of poking and prodding. They take much more careful planning before trying to change. And more often than not, casting doesn't fix those.

Now I don't mean to be rude or anything, but are you sure you're up for this? And are you sure it's really necessary to do it?
21 Jan, 2007, gazzy123 wrote in the 7th comment:
Votes: 0
Yeah.. got it working with g++ now and with -Wall -Werror flags and not a single error/warning :)
Now I just need to remove the hash_string on stock rom and replace with smaugs

Thats gonna be hard
21 Jan, 2007, gazzy123 wrote in the 8th comment:
Votes: 0
Ok, now I got problems… I tried to load socials with the fread_string_nohash and fread_string_hash but they both got the error that the string was too long. what should I do? any ideas?

lol,, nothing works now instat crash on startup,, has to do with all the loading I guess mobs/objs etc.
22 Jan, 2007, kiasyn wrote in the 9th comment:
Votes: 0
If your socials are that long something is probably corrupted and its reading the entire file into one string.
22 Jan, 2007, gazzy123 wrote in the 10th comment:
Votes: 0
and now this when killing a mob:

==752== by 0x8075DCC: multi_hit(char_data*, char_data*, int) (fight.c:320)
==752== by 0x807576A: violence_update() (fight.c:100)
==752== by 0x80BF7CB: update_handler() (update.c:1264)
==752== by 0x8069355: game_loop_unix(int) (comm.c:846)
==752== by 0x8068EB4: main (comm.c:449)
==752== Address 0x1BEEB268 is 216 bytes inside a block of size 380 free'd
==752== at 0x1B904B04: free (vg_replace_malloc.c:152)
==752== by 0x80B0870: free_char(char_data*) (recycle.c:429)
==752== by 0x8080C33: extract_char(char_data*, bool) (handler.c:1979)
==752== by 0x8078EA1: raw_kill(char_data*) (fight.c:2084)
==752== by 0x80776DA: damage(char_data*, char_data*, int, int, int, bool) (fight.c:1091)
==752== by 0x8076A63: one_hit(char_data*, char_data*, int, bool) (fight.c:731)
==752== by 0x8075DCC: multi_hit(char_data*, char_data*, int) (fight.c:320)
==752== by 0x807576A: violence_update() (fight.c:100)
==752== by 0x80BF7CB: update_handler() (update.c:1264)
==752== by 0x8069355: game_loop_unix(int) (comm.c:846)
==752== by 0x8068EB4: main (comm.c:449)
22 Jan, 2007, bbailey wrote in the 11th comment:
Votes: 0
There are many instances in many codebases where the free-list implementation has allowed a lot of memory abuse to go unnoticed. Combat is the most prevalent offender in this case. With the free lists, a mob could be killed and extracted, placing its structure on the free list. Since the memory was still intact, subsequent references to that memory would return (typically) valid data, as there would not usually be any new mobiles created during the same game loop that would reclaim that structure from the free list.

However, when you're doing full deallocation at the point of extraction, the mobile is extracted from the char list and free'd when it dies and that memory location is no longer valid. Any subsequent attempts to reference that memory will give you undefined results.

In short, you're going to need a way to consistently track when a structure is free'd and -not- reference any pointer that now points to an undefined position in memory.
22 Jan, 2007, gazzy123 wrote in the 12th comment:
Votes: 0
Ok, I'm about to give up have checked group_gain for references to non-allocated memory

==18166== Invalid read of size 4
==18166== at 0x8079CB8: group_gain(char_data*, char_data*) (fight.c:2183)
==18166== by 0x8077EF3: damage(char_data*, char_data*, int, int, int, bool) (fight.c:1059)
==18166== by 0x807745B: one_hit(char_data*, char_data*, int, bool) (fight.c:736)
==18166== by 0x80767C4: multi_hit(char_data*, char_data*, int) (fight.c:325)
==18166== by 0x8076161: violence_update() (fight.c:105)
==18166== by 0x80C1DA7: update_handler() (update.c:1264)
==18166== by 0x8069ACD: game_loop_unix(int) (comm.c:846)
==18166== by 0x806962C: main (comm.c:449)
==18166== Address 0x1BF7A1D8 is 216 bytes inside a block of size 380 free'd
==18166== at 0x1B904B04: free (vg_replace_malloc.c:152)
==18166== by 0x807917D: free_fight(char_data*) (fight.c:1807)
==18166== by 0x80791BD: stop_fighting(char_data*, bool) (fight.c:1824)
==18166== by 0x8077ED9: damage(char_data*, char_data*, int, int, int, bool) (fight.c:1052)
==18166== by 0x807745B: one_hit(char_data*, char_data*, int, bool) (fight.c:736)
==18166== by 0x80767C4: multi_hit(char_data*, char_data*, int) (fight.c:325)
==18166== by 0x8076161: violence_update() (fight.c:105)
==18166== by 0x80C1DA7: update_handler() (update.c:1264)
==18166== by 0x8069ACD: game_loop_unix(int) (comm.c:846)
==18166== by 0x806962C: main (comm.c:449)

(gdb) bt
#0 group_gain (ch=0x1bf7a100, victim=0x1be96468) at fight.c:2183
#1 0x08077ef4 in damage (ch=0x1bf7a100, victim=0x1be96468, dam=28, dt=1017, dam_type=1, show=true) at fight.c:1059
#2 0x0807745c in one_hit (ch=0x1bf7a100, victim=0x1be96468, dt=1017, secondary=104) at fight.c:736
#3 0x080767c5 in multi_hit (ch=0x1bf7a100, victim=0x1be96468, dt=-1) at fight.c:325
#4 0x08076162 in violence_update () at fight.c:105
#5 0x080c1da8 in update_handler () at update.c:1264
#6 0x08069ace in game_loop_unix (control=4) at comm.c:846
#7 0x0806962d in main (argc=2, argv=0x52bfeaa4) at comm.c:449

(gdb) frame 0
#0 group_gain (ch=0x1bf7a100, victim=0x1be96468) at fight.c:2183
2183 if ( IS_NPC(ch) || victim == ch )
(gdb) info locals
buf = "@o¹\033\f\207¿RX\207¿R\000\207¿RoÊ´\033\f\207¿R¤Q÷\033ÀÕ´\033\000\000\000\000\000\000\000\000Ü\201\000\034λ´\033\230\207¿R\034\207¿RÌ,\000\034 \237÷\033¤Q÷\033@o¹\033T\207¿RX\207¿R\034\207¿R\201È´\033\236¾´\033në¶\033@o¹\033\224\207¿R\024\222¹\033h\207¿RÆ÷´\033\024\222¹\033\r\214¸\033X\207¿R\001\000\000\000\000\000\000\000\000\004\000\000öN\220\033\230\207¿R\001\000\000\000 ó¹\033\003\021\000\000lq\a°\034\000\000\000\001\000\000\000\000\000\000\000\002\000\000\000\004\000\000\000¨\207¿R¨f÷\033° ÷\033`I÷\033"…
gch = (CHAR_DATA *) 0x1be96468
gch_next = (CHAR_DATA *) 0x0
lch = (CHAR_DATA *) 0x0
xp = 0
members = 28
group_levels = 0
templevel = 468280424


this is the group_gain:

void group_gain( CHAR_DATA *ch, CHAR_DATA *victim )
{
char buf[MAX_STRING_LENGTH];
CHAR_DATA *gch, *gch_next;
CHAR_DATA *lch;
int xp;
int members;
int group_levels;
int templevel;

/*
* Monsters don't get kill xp's or alignment changes.
* P-killing doesn't help either.
* Dying of mortal wounds or poison doesn't give xp to anyone!
*/

if (!ch || !victim)
{
bugf("%s have nonexistent ch and/or victim",__FUNCTION__);
return;
}
if ( IS_NPC(ch) || victim == ch )
return;


members = 0;
group_levels = 0;
for ( gch = ch->in_room->people; gch ; gch = gch->next_in_room )
{
if ( is_same_group( gch, ch ) )
{
members++;
if (!IS_NPC(gch) && gch->level >= 90)
templevel = 90;
else
templevel = gch->level;

//group_levels += IS_NPC(gch) ? gch->level / 2 : gch->level;
group_levels += IS_NPC(gch) ? templevel / 2 : templevel;
}
}

if ( members == 0 )
{
bugf( "Group_gain: members %d.", members );
members = 1;
if (!IS_NPC(ch) && ch->level >= 90)
templevel = 90;
else
templevel = ch->level;

//group_levels = ch->level ;
group_levels = templevel ;
}

lch = ch->leader ? ch->leader : ch;

for ( gch = ch->in_room->people; gch ; gch = gch_next )
{
OBJ_DATA *obj;
OBJ_DATA *obj_next;

gch_next = gch->next_in_room;

//if ( !is_same_group( gch, ch ) || IS_NPC(gch))
if ( !is_same_group( gch, lch ) || IS_NPC(gch))
continue;

/*
if (IS_CLAN(gch) && !IS_CLAN(lch))
{
send_to_char("You cant group with this person.\n\r",ch);
continue;
}

if (IS_CLAN(lch) && !IS_CLAN(gch))
{
send_to_char("You cant group with this person.\n\r",ch);
continue;
}
*/
if ( gch->level - lch->level >= 5 )
{
send_to_char( "You are too high for this group.\n\r", gch );
continue;
}

if ( gch->level - lch->level <= -5 )
{
send_to_char( "You are too low for this group.\n\r", gch );
continue;
}

xp = xp_compute( gch, victim, group_levels );
if (gch->level >= 90)
{
gain_primal(gch,xp);
}
else
{
sprintf( buf, "{GYou receive{W =%d= {GExperience from that kill.{x\n\r", xp );
send_to_char( buf, gch );
gain_exp( gch, xp );
}

for ( obj = ch->carrying; obj != NULL; obj = obj_next )
{
obj_next = obj->next_content;
if ( obj->wear_loc == WEAR_NONE )
continue;

if ( ( IS_OBJ_STAT(obj, ITEM_ANTI_EVIL) && IS_EVIL(ch) )
|| ( IS_OBJ_STAT(obj, ITEM_ANTI_GOOD) && IS_GOOD(ch) )
|| ( IS_OBJ_STAT(obj, ITEM_ANTI_NEUTRAL) && IS_NEUTRAL(ch) ) )
{
act( "You are zapped by $p.", ch, obj, NULL, TO_CHAR );
act( "$n is zapped by $p.", ch, obj, NULL, TO_ROOM );
obj_from_char( obj );
obj_to_room( obj, ch->in_room );
}
}
}

//free_string(buf);
//DISPOSE(buf);
return;
}



from what I can see it's the IS_NPC() that isn't working.

#define IS_NPC(ch) (IS_SET((ch)->act, ACT_IS_NPC))
#define IS_SET(flag, bit) ((flag) & (bit))

but it seems right.
23 Jan, 2007, Omega wrote in the 13th comment:
Votes: 0
make sure the ch isn't null!

since you converted to calloc/free, you now have to worry about things being 'freed' where-as you nolonger have the free_lists, so you have to be careful of how you write your code, make-sure that nothing is called that affect ch after it was extracted.
23 Jan, 2007, gazzy123 wrote in the 14th comment:
Votes: 0
I did bt it and victim and ch exists

(gdb) frame 2
#2 group_gain (ch=0x1bf76670, victim=0x1beea448) at fight.c:2187
2187 if (IS_NPC(ch))
(gdb) p (act_bit_name(ch->act))
$4 = 0x81199e1 "player autoexit holy_light no_summon colour"
(gdb) p (act_bit_name(victim->act))
$5 = 0x81199e1 "npc sentinel stay_area"

so I cannot understand why IS_NPC(ch) "is an Invalid read of size 4"

anyone have any clue?



also:

(gdb) frame 2
#2 group_gain (ch=0x1bf76670, victim=0x1beea448) at fight.c:2187
2187 if (IS_NPC(ch))
(gdb) p *ch
$9 = {next = 0x1bf70b08, next_in_room = 0x1beea448, master = 0x0, leader = 0x0, fighting = 0x1beea448, reply = 0x0,
pet = 0x0, mprog_target = 0x0, memory = 0x0, spec_fun = 0, pIndexData = 0x0, desc = 0x1bf70fd8, affected = 0x0,
pnote = 0x0, carrying = 0x1bf780e8, on = 0x0, in_room = 0x1be3b380, was_in_room = 0x0, from_room = 0x0, zone = 0x0,
pcdata = 0x1bf76820, gen_data = 0x0, events = 0x0, valid = true, name = 0x1bf77448 "Stonefist", id = 1165085813,
version = 5, short_descr = 0x0, long_descr = 0x0, description = 0x1bf774d8 "hmmmz\n\r", backup_name = 0x0,
backup_desc = 0x0, backup_prompt = 0x0, prompt = 0x1bf77518 "{W<{x#hhp{W|{x#mm{W|{x#vmv{W>{x ", prefix = 0x0,
lasthost = 0x1bf7bd70 "192.168.0.3", group = 0, clan = 5, sex = 1, Class = 0, race = 2, level = 100, trust = 0,
played = 453905, lines = 18, logon = 1169579227, timer = 0, wait = 1, daze = 0, hit = 11760, max_hit = 11760,
mana = 10000, max_mana = 10000, move = 500000, max_move = 500000, gold = 0, silver = 330, exp = 1000, act = 598024,
act2 = 0, comm = 286720, wiznet = 131149, imm_flags = 0, res_flags = 2, vuln_flags = 33554432, invis_level = 0,
incog_level = 0, affected_by = 512, position = 8, practice = 5, train = 2, carry_weight = 540, carry_number = 15,
saving_throw = 0, alignment = 1000, hitroll = 0, damroll = 0, armor = {100, 100, 100, 100}, wimpy = 0, perm_stat = {12,
17, 13, 15, 11}, mod_stat = {0, 0, 0, 0, 0}, form = 2101377, parts = 2047, size = 1, material = 0x0, off_flags = 0,
damage = {0, 0, 0}, dam_type = 17, start_pos = 0, default_pos = 0, mprog_delay = 0, extra = 0, intercept_var = 0x0,
intercept_proceed = 0x0, temp = 0x0, num_damage = 0, num_attacks = 41, num_dodges = 41, num_parries = 41, num_hits = -1,
briefdamage = 1}
(gdb)

(gdb) p *victim
$10 = {next = 0x1beea298, next_in_room = 0x1beea298, master = 0x0, leader = 0x0, fighting = 0x0, reply = 0x0, pet = 0x0,
mprog_target = 0x0, memory = 0x0, spec_fun = 0, pIndexData = 0x1be393b8, desc = 0x0, affected = 0x0, pnote = 0x0,
carrying = 0x0, on = 0x0, in_room = 0x1be3b380, was_in_room = 0x0, from_room = 0x0, zone = 0x0, pcdata = 0x0,
gen_data = 0x0, events = 0x0, valid = true, name = 0x1be39598 "swamp snail", id = 503, version = 0,
short_descr = 0x1be395e0 "{xa {x{yG{Gi{ga{Gnt s{yn{gai{yl{x",
long_descr = 0x1be39640 "{xa {x{yG{Gi{ga{Gnt s{yn{gai{yl{x stands here waiting for some leafs.\n\r", description = 0x0,
backup_name = 0x0, backup_desc = 0x0, backup_prompt = 0x0, prompt = 0x0, prefix = 0x0, lasthost = 0x0, group = 0,
clan = 0, sex = 0, Class = 0, race = 23, level = 110, trust = 0, played = 0, lines = 22, logon = 1169579220, timer = 0,
wait = 0, daze = 0, hit = -35, max_hit = 1627, mana = 0, max_mana = 0, move = 100, max_move = 100, gold = 0, silver = 0,
exp = 0, act = 67, act2 = 0, comm = 7340032, wiznet = 0, imm_flags = 0, res_flags = 8456195, vuln_flags = 384,
invis_level = 0, incog_level = 0, affected_by = 0, position = 0, practice = 0, train = 0, carry_weight = 0,
carry_number = 0, saving_throw = 0, alignment = -1000, hitroll = 10, damroll = 2, armor = {0, 0, 0, 0}, wimpy = 0,
perm_stat = {28, 25, 25, 27, 26}, mod_stat = {0, 0, 0, 0, 0}, form = 293601345, parts = 10554425, size = 5,
material = 0x1bbcfa38 "unknown", off_flags = 672, damage = {1, 20, 0}, dam_type = 11, start_pos = 9, default_pos = 9,
mprog_delay = 0, extra = 0, intercept_var = 0x0, intercept_proceed = 0x0, temp = 0x0, num_damage = 0, num_attacks = 0,
num_dodges = 0, num_parries = 0, num_hits = -1, briefdamage = 0}
(gdb)
0.0/14