Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ SWRiP:mprog_driver.. Address out of bound problem...

SWRiP:mprog_driver.. Address out of bound problem...

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by LewisSharp   (7 posts)  Bio
Date Mon 03 Sep 2007 11:56 PM (UTC)

Amended on Tue 04 Sep 2007 12:11 AM (UTC) by LewisSharp

Message
Hi there, I will try to be as explicite and specific as I can be on this issue that has raised to me recently.

Situation report:
I recently reinstalled linux on my server (Ubuntu, I was on Debian before) because I screwed up with it too much. So, now I'm back online, I recompiled the mud, though I had to installed G++, gpp, etc... so I could 'make all' and have it work, I also had to installed library missing. Everything was fixed to that level. Now, I launch the mud, it's stable and everything looks perfect. Then, boom, crash, a core file it created and I hit gdb...

Loaded symbols for /lib/tls/i686/cmov/libnss_files.so.2
#0  0x080febc7 in mprog_next_command (clist=0xbf785398 <Address 0xbf785398 out of bounds>) at mud_prog.c:156
156       while ( *pointer != '\n' && *pointer != '\0' )
(gdb) bt
#0  0x080febc7 in mprog_next_command (clist=0xbf785398 <Address 0xbf785398 out of bounds>) at mud_prog.c:156
#1  0x0810365f in mprog_driver (
    com_list=0x8785398 "smile\n\rmpsleep 5\n\rsay Hello. Welcome to the Diktat's office.\n\rsay &wThe Diktat is very busy, but I'd be willing to take a message.&W&w\n\rendif\n\r", mob=0x8774348, actor=0x87726d8, obj=0x0, vo=0x0, single_step=false) at mud_prog.c:1460
#2  0x08105a4b in mpsleep_update () at mud_prog.c:1896
#3  0x0814b32a in update_handler () at update.c:2373
#4  0x080b2175 in game_loop () at comm.c:588
#5  0x080b287e in main (argc=2, argv=0xbfeb9804) at comm.c:263
Current language:  auto; currently c++
(gdb)

1450      while ( TRUE )
1451      {
1452        /* With these two lines, cmnd becomes the current line from the prog,
(gdb)
1453           and command_list becomes everything after that line. */
1454        cmnd         = command_list;
1455            if (!command_list) {
1456                    progbug( "Command list unreadable", mob );
1457                    --prog_nest;
1458                    return;
1459            }
1460        command_list = mprog_next_command( command_list );
1461
1462        /* Are we at the end? */
(gdb)
1463        if ( cmnd[0] == '\0' )
1464        {
1465          if ( ifstate[iflevel][IN_IF] || ifstate[iflevel][IN_ELSE] )
1466          {
1467            progbug( "Missing endif", mob );
1468          }
1469          --prog_nest;
1470          return;
1471        }
(gdb) p tmpcmndlst
$1 = "smile\n\rmpsleep 5\n\rsay Hello. Welcome to the Diktat's office.\n\rsay &wThe Diktat is very busy, but I'd be willing to take a message.&W&w\n\rendif\n\r\000\000\000\000\000\000\000\000\000`9ڷ", '\0' <repeats 12 times>, "\021\000\000\000\224�η$\bη\000\000\021\000\005\000\000\000\000\000\000\000�\212۷\000\000\000\000�\226"...
(gdb) p command_list
$2 = 0xbf77de40 <Address 0xbf77de40 out of bounds>

(sleep_update...)
1887            mpsleep = first_mpsleep;
1888            while (mpsleep) { // Find progs to continue
1889                    if (--mpsleep->timer <= 0) {
1890                            current_mpsleep = mpsleep;
1891                            if (mpsleep->type == MP_ROOM)
1892                                    rset_supermob(mpsleep->room);
1893                            else if (mpsleep->type == MP_OBJ)
1894                                    set_supermob(mpsleep->obj);
1895                            mprog_driver(mpsleep->com_list, mpsleep->mob, mpsleep->actor,
1896                            mpsleep->obj, mpsleep->vo, mpsleep->single_step);
(gdb)
1897                            release_supermob();
1898                            tmpMpsleep = mpsleep;
1899                            mpsleep = mpsleep->next;
1900                            STRFREE(tmpMpsleep->com_list);
1901                            UNLINK(tmpMpsleep, first_mpsleep, last_mpsleep, next, prev);
1902                            DISPOSE(tmpMpsleep);
1903                            continue;
1904                    }
1905                    mpsleep = mpsleep->next;
1906            }
(gdb) set print pretty
(gdb) p *mpsleep
Cannot access memory at address 0xffffffe8
(gdb) p first_mpsleep
$3 = (MPSLEEP_DATA *) 0x877faa8
(gdb) p *first_mpsleep
$4 = {
  next = 0x0,
  prev = 0x0,
  timer = 0,
  type = MP_MOB,
  room = 0x0,
  ignorelevel = 0,
  iflevel = 1,
  ifstate = {{false, false, false, false}, {true, false, false, false}, {
      false, false, false, false} <repeats 18 times>},
  com_list = 0x8785398 "smile\n\rmpsleep 5\n\rsay Hello. Welcome to the Diktat's office.\n\rsay &wThe Diktat is very busy, but I'd be willing to take a message.&W&w\n\rendif\n\r",
  mob = 0x8774348,
  actor = 0x87726d8,
  obj = 0x0,
  vo = 0x0,
  single_step = false
}

Sometimes, msleep is ok, com_list also, but Command_List always is the one with the address out of bound problem in all cases I've seen up to now. I've been trying to add if checks to avoid crashing, but can't seems to find a way to prevent it. So, if anyone has any idea how I can fix this, that would be a great help.

Thank you for your time.

Aramis.
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #1 on Tue 04 Sep 2007 12:03 AM (UTC)
Message
Have you tried running it in gdb, instead of using the core? It'll be easier to step through stuff.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #2 on Tue 04 Sep 2007 12:04 AM (UTC)
Message
Since it seems that you run your own server, I would recommend installing valgrind (which is in the Ubuntu repositories) and running your code through that. It will be the quickest way to figure out where your memory is being corrupted.

One thing that might help make it easier to read the GDB output is to use the [code] forum tag; it means the code is indented which makes it much more readable. :)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by LewisSharp   (7 posts)  Bio
Date Reply #3 on Tue 04 Sep 2007 12:34 AM (UTC)
Message
Ok, I installed valgrind, launched it with :
valgrind --leak-check=true ../swrip 8000
It took about a minute to load up and open up for connection. I made so the mud would crash with the same error as before, there's a area that uses lots of mpsleep etc.. and that area is known to crash my mud easily since a few ago. Anyway, I got this output:

==14341== Conditional jump or move depends on uninitialised value(s)
==14341==    at 0x4008852: (within /lib/ld-2.3.6.so)
==14341==    by 0x426ADE9: (within /lib/tls/i686/cmov/libc-2.3.6.so)
==14341==    by 0x400B105: (within /lib/ld-2.3.6.so)
==14341==    by 0x426B937: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
==14341==    by 0x426CF4C: (within /lib/tls/i686/cmov/libc-2.3.6.so)
==14341==    by 0x400B105: (within /lib/ld-2.3.6.so)
==14341==    by 0x426D02D: __libc_dlopen_mode (in /lib/tls/i686/cmov/libc-2.3.6.so)
==14341==    by 0x424747D: __nss_lookup_function (in /lib/tls/i686/cmov/libc-2.3.6.so)
==14341==    by 0x424760E: (within /lib/tls/i686/cmov/libc-2.3.6.so)
==14341==    by 0x4248F86: __nss_hosts_lookup (in /lib/tls/i686/cmov/libc-2.3.6.so)
==14341==    by 0x424BBE8: gethostbyname_r (in /lib/tls/i686/cmov/libc-2.3.6.so)
==14341==    by 0x424B493: gethostbyname (in /lib/tls/i686/cmov/libc-2.3.6.so)
...
==14341== Invalid read of size 1
==14341==    at 0x80FEBC7: mprog_next_command(char*) (mud_prog.c:156)
==14341==    by 0x810365E: mprog_driver(char*, char_data*, char_data*, obj_data*, void*, bool) (mud_prog.c:1460)
==14341==    by 0x8105A4A: mpsleep_update() (mud_prog.c:1896)
==14341==    by 0x814B329: update_handler() (update.c:2373)
==14341==    by 0x80B2174: game_loop() (comm.c:588)
==14341==    by 0x80B287D: main (comm.c:263)
==14341==  Address 0xBEB50BD8 is not stack'd, malloc'd or (recently) free'd
==14341==
==14341== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==14341==  Access not within mapped region at address 0xBEB50BD8
==14341==    at 0x80FEBC7: mprog_next_command(char*) (mud_prog.c:156)
==14341==    by 0x810365E: mprog_driver(char*, char_data*, char_data*, obj_data*, void*, bool) (mud_prog.c:1460)
==14341==    by 0x8105A4A: mpsleep_update() (mud_prog.c:1896)
==14341==    by 0x814B329: update_handler() (update.c:2373)
==14341==    by 0x80B2174: game_loop() (comm.c:588)
==14341==    by 0x80B287D: main (comm.c:263)
==14341==
==14341== ERROR SUMMARY: 9 errors from 8 contexts (suppressed: 21 from 1)
==14341== malloc/free: in use at exit: 5,039,675 bytes in 52,678 blocks.
==14341== malloc/free: 56,536 allocs, 3,858 frees, 6,204,778 bytes allocated.
==14341== For counts of detected errors, rerun with: -v
==14341== searching for pointers to 52,678 not-freed blocks.
==14341== checked 5,721,224 bytes.
==14341==
==14341==
==14341== 20 bytes in 1 blocks are definitely lost in loss record 1 of 56
==14341==    at 0x401C7AA: calloc (vg_replace_malloc.c:279)
==14341==    by 0x80B9663: load_helps(area_data*, _IO_FILE*) (db.c:992)
==14341==    by 0x80BEE4D: load_area_file(area_data*, char*) (db.c:5524)
==14341==    by 0x80C32C5: boot_db() (db.c:747)
==14341==    by 0x80B27D3: main (comm.c:253)
==14341==
==14341==
==14341== 1,456 bytes in 52 blocks are definitely lost in loss record 26 of 56
==14341==    at 0x401C7AA: calloc (vg_replace_malloc.c:279)
==14341==    by 0x80B7122: load_repairs(area_data*, _IO_FILE*) (db.c:1880)
==14341==    by 0x80BEFDD: load_area_file(area_data*, char*) (db.c:5532)
==14341==    by 0x80C32C5: boot_db() (db.c:747)
==14341==    by 0x80B27D3: main (comm.c:253)
==14341==
==14341==
==14341== 1,664 bytes in 52 blocks are definitely lost in loss record 27 of 56
==14341==    at 0x401C7AA: calloc (vg_replace_malloc.c:279)
==14341==    by 0x80B7272: load_shops(area_data*, _IO_FILE*) (db.c:1840)
==14341==    by 0x80BEFAB: load_area_file(area_data*, char*) (db.c:5531)
==14341==    by 0x80C32C5: boot_db() (db.c:747)
==14341==    by 0x80B27D3: main (comm.c:253)
==14341==
==14341== LEAK SUMMARY:
==14341==    definitely lost: 3,140 bytes in 105 blocks.
==14341==      possibly lost: 0 bytes in 0 blocks.
==14341==    still reachable: 5,036,535 bytes in 52,573 blocks.
==14341==         suppressed: 0 bytes in 0 blocks.
==14341== Reachable blocks (those to which a pointer was found) are not shown.
==14341== To see them, rerun with: --show-reachable=yes


So, I'm new to valgrind and have little idea on how to use this info up. Any help would be nice.

And thank you already for the help given, really appreciate it.

Aramis.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #4 on Tue 04 Sep 2007 12:46 AM (UTC)
Message
OK, this wasn't quite as useful as I'd hoped, but at least we know now that there weren't corruption errors before the symptom occurs. (That's what valgrind is most useful for, besides memory leaks: it can tell you when you do bad things like double-frees, stack overflows, invalid writes, etc. Lots of nasty problems like this are caused by such errors.)

Here's the relevant valgrind output:

==14341== Invalid read of size 1
==14341==    at 0x80FEBC7: mprog_next_command(char*) (mud_prog.c:156)
==14341==    by 0x810365E: mprog_driver(char*, char_data*, char_data*, obj_data*, void*, bool) (mud_prog.c:1460)
==14341==    by 0x8105A4A: mpsleep_update() (mud_prog.c:1896)
==14341==    by 0x814B329: update_handler() (update.c:2373)
==14341==    by 0x80B2174: game_loop() (comm.c:588)
==14341==    by 0x80B287D: main (comm.c:263)
==14341==  Address 0xBEB50BD8 is not stack'd, malloc'd or (recently) free'd
==14341==
==14341== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==14341==  Access not within mapped region at address 0xBEB50BD8
==14341==    at 0x80FEBC7: mprog_next_command(char*) (mud_prog.c:156)
==14341==    by 0x810365E: mprog_driver(char*, char_data*, char_data*, obj_data*, void*, bool) (mud_prog.c:1460)
==14341==    by 0x8105A4A: mpsleep_update() (mud_prog.c:1896)
==14341==    by 0x814B329: update_handler() (update.c:2373)
==14341==    by 0x80B2174: game_loop() (comm.c:588)
==14341==    by 0x80B287D: main (comm.c:263)



So it looks like we need to look at at 0x80FEBC7: mprog_next_command(char*) (mud_prog.c:156).
Could you paste that function and indicate which line is #156?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by LewisSharp   (7 posts)  Bio
Date Reply #5 on Tue 04 Sep 2007 12:51 AM (UTC)
Message

char *mprog_next_command( char *clist )
{
  char *pointer = clist;
156->  while ( *pointer != '\n' && *pointer != '\0' )
  {
    if ( *pointer == '+' )
    {
      *pointer = ' ';
      pointer++;
      while ( *pointer == ' ' )
        pointer++;
      if ( *pointer == '\n' ) 
      {
        *pointer = '~';
        pointer++;
        if ( *pointer == '\r' )
          *pointer = '~';
      }
    }
    pointer++;
  }
  if ( *pointer == '\n' )
    *pointer++ = '\0';
  if ( *pointer == '\r' )
    *pointer++ = '\0';
  return ( pointer );
}

and called from:

void mprog_driver {
  char tmpcmndlst[ MAX_STRING_LENGTH ];
  char *command_list;
  char *cmnd;
  ...
  MPSLEEP_DATA *mpsleep = NULL;
  ...
  count = 0;
  for ( vch = mob->in_room->first_person; vch; vch = vch->next_in_room )
    if ( !IS_NPC( vch ) )
      {
        if ( number_range( 0, count ) == 0 )
	  rndm = vch;
        count++;
      }
  strcpy( tmpcmndlst, com_list );
  command_list = tmpcmndlst;
  	/* mpsleep - Restore the environment -rkb */
	if (current_mpsleep) {
		ignorelevel = current_mpsleep->ignorelevel;
		iflevel = current_mpsleep->iflevel;

		if (single_step)
			mob->mpscriptpos = 0;

		/*for (count = 0; count <= MAX_IFS; count++)
			for (count2 = 0; count2 < DO_ELSE; count2++)//*/
		for (count = 0; count <= MAX_IFS; count++)
			for (count2 = 0; count2 < DO_ELSE; count2++)//*/
				ifstate[count][count2] = current_mpsleep->ifstate[count][count2];
		current_mpsleep = NULL;
	}
  if ( single_step )
  {
    if ( mob->mpscriptpos > (int) strlen( tmpcmndlst ) )
       mob->mpscriptpos = 0;
    else
       command_list += mob->mpscriptpos;
    if ( *command_list == '\0' )
    {
	command_list = tmpcmndlst;
	mob->mpscriptpos = 0;
    }
  }
  /* From here on down, the function is all mine.  The original code
     did not support nested ifs, so it had to be redone.  The max 
     logiclevel (MAX_IFS) is defined at the beginning of this file, 
     use it to increase/decrease max allowed nesting.  -Narn 
  */
  while ( TRUE )
  {
    /* With these two lines, cmnd becomes the current line from the prog,
       and command_list becomes everything after that line. */
    cmnd         = command_list;
	if (!command_list || command_list[0] == '\0' || command_list == NULL) {
		progbug( "Command list unreadable", mob );
		--prog_nest;
		return;
	}
crash->    command_list = mprog_next_command( command_list );
    /* Are we at the end? */
    if ( cmnd[0] == '\0' )
    {
      if ( ifstate[iflevel][IN_IF] || ifstate[iflevel][IN_ELSE] )
      {
        progbug( "Missing endif", mob );
      }
      --prog_nest;
      return;
    }
}
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #6 on Tue 04 Sep 2007 01:00 AM (UTC)
Message
It looks like you might be getting bad input to the next_command function; it makes a few assumptions about when it's safe to step through the string. For instance, it advances several times when you have a '+' in the string, because it assumes there are other things that follow.

How about you try printing the clist string every time the function is entered; then we'll be able to see what it was in the moments leading up to the crash.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by LewisSharp   (7 posts)  Bio
Date Reply #7 on Tue 04 Sep 2007 01:16 AM (UTC)
Message
Well the output was massive and not really helpfull if you ask me, though here is the one near the crash:

Mon Sep  3 21:12:56 2007 :: clist: if ispc($n)
mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: endif
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: emote points a blaster at $n, "empty your pockets!"
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: emote points a blaster at $n, "empty your pockets!"
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: if ispc($n)
mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: endif
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: if ispc($n)
mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: endif
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: if ispc($n)
mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: endif
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: emote points a blaster at $n, "empty your pockets!"
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: if ispc($n)
mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: endif
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: if ispc($n)
mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: endif
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: if ispc($n)
mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: endif
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: if ispc($n)
mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: mpkill $n
endif
.
Mon Sep  3 21:12:56 2007 :: clist: endif
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: emote points a blaster at $n, "empty your pockets!"
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: emote points a blaster at $n, "empty your pockets!"
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: emote points a blaster at $n, "empty your pockets!"
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: emote points a blaster at $n, "empty your pockets!"
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: say Greetings. A ticket to ride the train will cost you 250 credits
.
Mon Sep  3 21:12:56 2007 :: clist: .
Mon Sep  3 21:12:56 2007 :: clist: say I had to remake because I didn't obey the rules.
snif
.
Mon Sep  3 21:12:57 2007 :: Log Aramis: goto 34700
Mon Sep  3 21:13:00 2007 :: clist: if ispc($n)
mpkill $n
endif
.
Mon Sep  3 21:13:00 2007 :: clist: mpkill $n
endif
.
Mon Sep  3 21:13:00 2007 :: clist: endif
.
Mon Sep  3 21:13:00 2007 :: clist: .
Mon Sep  3 21:13:00 2007 :: clist: if ispc($n)
mpkill $n
endif
.
Mon Sep  3 21:13:00 2007 :: clist: mpkill $n
endif
.
Mon Sep  3 21:13:00 2007 :: clist: endif
.
Mon Sep  3 21:13:00 2007 :: clist: .
Mon Sep  3 21:13:00 2007 :: clist: if ispc($n)
mpkill $n
endif
.
Mon Sep  3 21:13:00 2007 :: clist: mpkill $n
endif
.
Mon Sep  3 21:13:00 2007 :: clist: endif
.
Mon Sep  3 21:13:00 2007 :: clist: .
Mon Sep  3 21:13:00 2007 :: clist: say Greetings. A ticket to ride the train will cost you 250 credits
.
Mon Sep  3 21:13:00 2007 :: clist: .
Mon Sep  3 21:13:00 2007 :: clist: snif
.
Mon Sep  3 21:13:04 2007 :: clist: emote giggles playfully and smacks a ball towards his friends.
.
Mon Sep  3 21:13:04 2007 :: clist: .
Mon Sep  3 21:13:04 2007 :: clist: emote grumbles as she walks.
mpsleep 5
say Where is he? I swear if he's at the damn arenas...
.
Mon Sep  3 21:13:04 2007 :: clist: mpsleep 5
say Where is he? I swear if he's at the damn arenas...
.
Mon Sep  3 21:13:04 2007 :: clist: mutter
say I hope he comes in first...or else my wife is going to kill me...
.
Mon Sep  3 21:13:04 2007 :: clist: say I hope he comes in first...or else my wife is going to kill me...
.
Mon Sep  3 21:13:04 2007 :: clist: .
Mon Sep  3 21:13:04 2007 :: clist: say Greetings. A ticket to ride the train will cost you 250 credits
.
Mon Sep  3 21:13:04 2007 :: clist: .
Mon Sep  3 21:13:04 2007 :: clist: say I was level 90, but used the name Joe.
say I had to remake because I didn't obey the rules.
snif
.
Segmentation fault (core dumped)

Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #8 on Tue 04 Sep 2007 01:50 AM (UTC)
Message
i remember having problems with that snippet for the + thing to make multiple line commands, my version doesn't crash, try this and see if it still crashes.


char *mprog_next_command( char *clist )
{
  bool Append = FALSE;
  char *pointer = clist;

  while ( *pointer != '\0' )
  {
    if (Append == FALSE && (*pointer == '\n' || *pointer == '\r'))
       break;
    if (Append == TRUE && *pointer != '\n' && *pointer != '\r')
       Append = FALSE;
    else if (Append == TRUE && (*pointer == '\n' || *pointer == '\r'))
    {
/*
       A tilde is one symbol we can be absolutely certain never
       to have as part of a prog, so can replace the returns with
       tildes, and then later we will strip all tildes from the
       output before its parse the final time.
*/
      *pointer = '~';
    }
    if ( *pointer == '+' )
    {
      Append = TRUE;
      *pointer = ' ';
    }
    pointer++;
  }
  if ( *pointer == '\n' )
    *pointer++  = '\0';
  if ( *pointer == '\r' )
    *pointer++ = '\0';

  return ( pointer );
}
Top

Posted by LewisSharp   (7 posts)  Bio
Date Reply #9 on Tue 04 Sep 2007 02:10 AM (UTC)
Message
Nope, I believe the problem is higher then mprog_next_command, I'd even say higher then mprog_driver to some point as sometimes mpsleep_update send mprog_driver an out of bouds cmd_list arg which is translated into clist later on.


void mpsleep_update() {
	MPSLEEP_DATA *mpsleep;
	MPSLEEP_DATA *tmpMpsleep;
	bool delete_it;
	mpsleep = first_mpsleep;
	while (mpsleep) {
		delete_it = FALSE;
		if (mpsleep->mob)
			delete_it = char_died(mpsleep->mob);
		if (mpsleep->actor && !delete_it)
			delete_it = char_died(mpsleep->actor);
		if (mpsleep->obj && !delete_it)
			delete_it = obj_extracted(mpsleep->obj);
		if (delete_it) {
			log_string("mpsleep_update - Deleting expired prog.");
			tmpMpsleep = mpsleep;
			mpsleep = mpsleep->next;
			STRFREE(tmpMpsleep->com_list);
			UNLINK(tmpMpsleep, first_mpsleep, last_mpsleep, next, prev);
			DISPOSE(tmpMpsleep);
			continue;
		}
		mpsleep = mpsleep->next;
	}

	mpsleep = first_mpsleep;
	while (mpsleep) { // Find progs to continue 
		if (--mpsleep->timer <= 0) {
			current_mpsleep = mpsleep;
			if (mpsleep->type == MP_ROOM)
				rset_supermob(mpsleep->room);
			else if (mpsleep->type == MP_OBJ)
				set_supermob(mpsleep->obj);
			mprog_driver(mpsleep->com_list, mpsleep->mob, mpsleep->actor,
			mpsleep->obj, mpsleep->vo, mpsleep->single_step);
			release_supermob();
			tmpMpsleep = mpsleep;
			mpsleep = mpsleep->next;
			STRFREE(tmpMpsleep->com_list);
			UNLINK(tmpMpsleep, first_mpsleep, last_mpsleep, next, prev);
			DISPOSE(tmpMpsleep);
			continue;
		}
		mpsleep = mpsleep->next;
	}
}

sometimes mpsleed is the one out of bound when this is launched :

mprog_driver(mpsleep->com_list, mpsleep->mob, mpsleep->actor,	mpsleep->obj, mpsleep->vo, mpsleep->single_step);


Though I have no idea what could cause this really. Been trying to figure this out for the last 4 days :)
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #10 on Tue 04 Sep 2007 02:21 AM (UTC)

Amended on Tue 04 Sep 2007 02:22 AM (UTC) by Gohan_TheDragonball

Message
well if trying out my mprog_next_command didn't work i don't know what will, considering your backtrace points right to that function as the point that it crashes. try checking this topic out, apply all the stuff talked about, and try again:

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=2646
Top

Posted by LewisSharp   (7 posts)  Bio
Date Reply #11 on Tue 04 Sep 2007 03:14 AM (UTC)
Message
Yeah that was the link I used when I installed mpsleep. Though, for some reasons I had to change it because it was ignoring else statements or crashing on them. Modification included only the following :

void mprog_driver(...
  -bool ifstate[MAX_IFS][DO_ELSE ];
  +bool ifstate[MAX_IFS][ DO_ELSE + 1 ];
  ...
		-for (count = 0; count < MAX_IFS; count++)
			for (count2 = 0; count2 < DO_ELSE; count2++)
		+for (count = 0; count <= MAX_IFS; count++)
			for (count2 = 0; count2 < DO_ELSE; count2++)
  ...
	if (!str_prefix("mpsleep", cmnd) ) {
		CREATE(mpsleep, MPSLEEP_DATA, 1);

		/* State variables */ 
		mpsleep->ignorelevel = ignorelevel; 
		mpsleep->iflevel = iflevel; 

		-for (count = 0; count < MAX_IFS; count++)
		+for (count = 0; count <= MAX_IFS; count++)


In anycase, the mud is back and stable, all I need to do is do mprog testing with lots of if and else to see if I'm back to program not doing the whole thing. Thanks again for your time and help and I'll never understand why this was working a week ago on Debian, and no longer on Ubuntu...

For some reason, complicated programs run ok.. tested this one for example :
>greet_prog 100
if isnpc($n)
mpecho you are a pc
mpsleep 10
mpecho woot
mpsleep 5
mpecho else now!
else
mpsleep 1
mpecho w
mpsleep 1
mpecho oo
mpsleep 1
mpecho t
mpsleep 5
mpecho you are here!
mpsleep 5
say you arent a pc!
endif

and I have no problem with else like I did before, it work perfectly. Sometimes I can just not understand certain changes into a computer's mind to work things up one way, then an other the next day. :)

So again, thank you, I think this is finally a fixed issue for me.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #12 on Tue 04 Sep 2007 05:43 AM (UTC)
Message
Quote:
Sometimes I can just not understand certain changes into a computer's mind to work things up one way, then an other the next day. :)

It's the binary goblins, I tell you. :)

http://www.binarygoblins.com/images/binary-goblin.jpg

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Gohan_TheDragonball   USA  (183 posts)  Bio
Date Reply #13 on Tue 04 Sep 2007 08:11 AM (UTC)
Message

  +bool ifstate[MAX_IFS][ DO_ELSE + 1 ];
  ...
		+for (count = 0; count <= MAX_IFS; count++)
		    for (count2 = 0; count2 < DO_ELSE; count2++)


umm i think you have it backwards, it needs to be < for Max_ifs part and <= for do_else part, using < for do_else will completely ignore else cases, and using <= for max_ifs part will take you out of the arrays bounds and crash.
Top

Posted by LewisSharp   (7 posts)  Bio
Date Reply #14 on Tue 04 Sep 2007 03:35 PM (UTC)
Message
As I was saying, strangely enough as it is, elses are not being ignored so I guess the modification to <= wont be necessary.

And I don't wanna imagine the day we will have holographic projector connected to our computer with that Goblin running aroung the place. :)
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


48,947 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.