Re: Little problem with creating structures.

From: Templar Viper (templarviper@hotmail.com)
Date: 06/28/02


From: "Ronald Fenner" <abbadon@MAC.COM>
> >   clear_object(OLC_OBJ(d));
> >   OLC_OBJ(d)->name = strdup("unfinished object");
> >   OLC_OBJ(d)->description = strdup("An unfinished object is lying
> > here.");
> >   OLC_OBJ(d)->short_description = strdup("an unfinished object");
> >
> >   for(counter=0;counter<MAX_WEAPON_SPELLS;counter++) {
> >     OLC_OBJ(d)->wpn_spells[counter].text = strdup("$p leaps to action
> > with an attack of its own!");
> >     OLC_OBJ(d)->wpn_spells[counter].text2 = strdup("In your hands, $p
> > leaps to action with an attack of its own!");
> >
> if this was a copy and paste you might want to go through and change all
> the strdup to str_dup and see if that helps looking over my code base
> with olc i did not find a single instance of strdup but tons of str_dup.
>
> > However, when this function is called, the mud crashes with the
> > following gdb output:
> >
> > Program received signal SIGSEGV, Segmentation fault.
> > 0x6108d3e5 in _libkernel32_a_iname ()
> >
> >
> a backtrace of the stack would be nice since it would show you the line
> of YOUR code that initiated the crash and would one could concentrate on
> that line and figure out what went wrong. just seeing that you called a
> library routine wrong and ended up crashing in kernel space doesn't go
> very far to pinpointing the problem.

Here is the result of my backtrace:
I'm running cygwin on windows 98.

#0  0x6108d3e5 in _libkernel32_a_iname ()
#1  0x008bf4bc in ?? ()
#2  0x610908bf in _libkernel32_a_iname ()
#3  0x6108fec7 in _libkernel32_a_iname ()
#4  0x61092b55 in _libkernel32_a_iname ()
#5  0x0044428f in vwrite_to_output (t=0x10089530,
    format=0x49a23c "[%s%d%s] Spell: %s%20s%s Level: %s%3d%s Percent:
%s%3d%s En
gage: %s%-3s%s\r\n[%s%d%s] Action string1: %s%s%s\r\n[%s%d%s] Action
string2: %s
%s%s\r\n\r\n", args=0x8bf63c) at comm.c:1241
#6  0x00444256 in write_to_output (t=0x10089530,
    txt=0x49a23c "[%s%d%s] Spell: %s%20s%s Level: %s%3d%s Percent: %s%3d%s
Engag
e: %s%-3s%s\r\n[%s%d%s] Action string1: %s%s%s\r\n[%s%d%s] Action string2:
%s%s%
s\r\n\r\n") at comm.c:1223
#7  0x0049a3db in oedit_disp_weapon_spells (d=0x10089530) at oedit.c:665
#8  0x0049ae79 in oedit_parse (d=0x10089530, arg=0x8bfa7c "w") at
oedit.c:819
#9  0x00488ea9 in nanny (d=0x10089530, arg=0x8bfa7c "w") at
interpreter.c:1450
#10 0x00443640 in game_loop (mother_desc=4) at comm.c:844
#11 0x004428f0 in init_game (port=4000) at comm.c:454
#12 0x00442719 in main (argc=1, argv=0x10031018) at comm.c:402
#13 0x61003f42 in _libkernel32_a_iname ()
#14 0x61004236 in _libkernel32_a_iname ()
#15 0x61004275 in _libkernel32_a_iname ()
#16 0x004bb4db in cygwin_crt0 ()
#17 0x0040103d in mainCRTStartup ()
#18 0xbff8b537 in _libkernel32_a_iname ()
#19 0xbff8b3e9 in _libkernel32_a_iname ()
#20 0xbff89dac in _libkernel32_a_iname ()
Cannot access memory at address 0x8335bfec

Now you may ask what the mud is trying to send to send_to_char, so
here's that piece of code:

write_to_output(d, "[%s%d%s] Spell: %s%20s%s Level: %s%3d%s Percent: %s%3d%s
Engage: %s%-3s%s\r\n"
                 "[%s%d%s] Action string1: %s%s%s\r\n"
        "[%s%d%s] Action string2: %s%s%s\r\n\r\n",
     cyn, counter+1, nrm,
  cyn, spell_info[OLC_OBJ(d)->wpn_spells[counter].spellnum].name ?
  spell_info[OLC_OBJ(d)->wpn_spells[counter].spellnum].name : "None" , nrm,
     cyn, OLC_OBJ(d)->wpn_spells[counter].level, nrm,
     cyn, OLC_OBJ(d)->wpn_spells[counter].percent, nrm,
  cyn, OLC_OBJ(d)->wpn_spells[counter].engage ? "yes" : "no" , nrm,
  cyn, counter+2, nrm, cyn, OLC_OBJ(d)->wpn_spells[counter].text, nrm,
  cyn, counter+3, nrm, cyn, OLC_OBJ(d)->wpn_spells[counter].text2, nrm);

As you can see, it tries to print the text2-string to the screen. I have no
idea what
causes these weird crashes.. After all, oedit_setup_new should handle this.
I'm
puzzled.. Any help or hints are appreciated. Thanks.

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT