Login
User Name:

Password:



Register

Forgot your password?
Hi - Clean SmaugFuss map/description issue..
Dec 15, 2024 7:29 pm
By Samson
AFKMud 2.2.4
Dec 10, 2024 4:09 pm
By Samson
I3 and IMC
Dec 8, 2024 6:35 pm
By Remcon
Ubuntu 22.04.5 LTS
Dec 5, 2024 5:10 pm
By Remcon
SmaugFUSS 1.8/1.9
Nov 29, 2024 11:46 am
By Remcon
SWFOTEFUSS 1.5.1
Author: Various
Submitted by: Samson
SWRFUSS 1.4.1
Author: Various
Submitted by: Samson
SmaugFUSS 1.9.5
Author: Various
Submitted by: Samson
AFKMud 2.2.4
Author: AFKMud Team
Submitted by: Samson
LOP 1.5
Author: Remcon
Submitted by: Remcon
Users Online
AhrefsBot, Bing

Members: 0
Guests: 57
Stats
Files
Topics
Posts
Members
Newest Member
494
3,808
19,707
588
Mortrex

Today's Birthdays
There are no member birthdays today.
» SmaugMuds » Codebases » SWR FUSS » AFKMud Board Snippet
Forum Rules | Mark all | Recent Posts

AFKMud Board Snippet
< Newer Topic :: Older Topic > Yes, it's another one :)

Pages:<< prev 1, 2 next >>
Post is unread #1 Jun 26, 2009 10:27 pm   
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

 
Alright I've got everything more or less working except for do_note_list, which is crashing the mud. Naturally...

Here's what the core file has to say about it:
(gdb) bt
#0  0x00287d53 in strlen () from /lib/i686/nosegneg/libc.so.6
#1  0x00257735 in _IO_vfprintf_internal (s=0xbfc8fa3c, format=0x81d9204 "%-2d) %c [ %-3d ] [%-15s] %-11s %s\r\n", ap=) at vfprintf.c:1560
#2  0x00278614 in _IO_vsnprintf (string=0xbfc8fb5a "1 ) * [ 1   ] [ate Author Subject\r\n", maxlen=131070,
		format=0x81d9204 "%-2d) %c [ %-3d ] [%-15s] %-11s %s\r\n", args=0xbfcafb68 "\001") at vsnprintf.c:120
#3  0x080dbb6b in ch_printf (ch=0x8c1f2d8, fmt=0x81d9204 "%-2d) %c [ %-3d ] [%-15s] %-11s %s\r\n") at color.c:1387
#4  0x080a4c72 in do_note_list (ch=0x8c1f2d8, argument=0xbfcefc8b "") at boards.c:1812
#5  0x08126d3d in interpret (ch=0x8c1f2d8, argument=0xbfcefc8b "") at interp.c:365
#6  0x080e0f65 in game_loop () at comm.c:728
#7  0x080e0498 in main (argc=4, argv=0xbfcffd64) at comm.c:418


Now, obviously the "ap=" part is what's killing it. And here's the offending line from boards.c:
ch_printf( ch, "%-2d) %c [ %-3d ] [%-15s] %-11s %s\r\n", count, unread, pnote->reply_count, pnote->date_stamp,
        pnote->sender ? pnote->sender : "--Error--", pnote->subject ? pnote->subject : "" );


Now unless I'm totally mistaken, and it's a pretty good bet that I am, the problem seems to be with the count variable, which is an int and has been initialized to 0...

It also seems like, at frame 2, it's shoving the following stuff from another, previous, call to ch_printf into the mix for some reason..
ch_printf( ch, "Num  %s Date Author Subject\r\n",  IS_BOARD_FLAG( board, BOARD_PRIVATE ) ? "" : "Replies " );


So umm, help? Please? :)

Post is unread #2 Jun 26, 2009 11:27 pm   
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,697
JoinedJan 1, 2002

 
Hmm. The random act of confusion here likely isn't helping anyone. *notes a QSFP issue for this*

On the rest, if someone doesn't beat me to it, I'll get back to you on that as I'm stuck on fixing part of the updated snippet and need to go feed on some goodies to refocus.

Post is unread #3 Jun 27, 2009 12:28 pm   
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

 
Check if pnote is in fact a valid pointer, and that all the fields that you're trying to print are themselves valid pointers.

Post is unread #4 Jun 29, 2009 3:38 pm   Last edited Jun 29, 2009 3:42 pm by Andril
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

 
All of the pointers are valid but for some reason it looks like the arguments aren't getting shoved into the va_list args variable in ch_printf and I'm starting to believe that's the issue. Though why it's only happening for this stuff is beyond me.

I also noticed the following:
format=0x81ecadc "Num  %s Date Author Subject\r\n", args=0xbfadc958 "a¼\036\b") at vsnprintf.c:117


That a¼\036\b doesn't look like it belongs there. It's supposed to be either nothing at all or "Replies".

Post is unread #5 Jun 29, 2009 6:37 pm   
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

 
I rather highly doubt that there's a bug in the standard libraries. Would you mind showing the gdb output where you print the value of each of the parameters sent to ch_printf?

Post is unread #6 Jun 30, 2009 5:36 pm   
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

 
And here you are. I set the board to private simply because there's less stuff to deal with, but I'm still getting the same error so...

1807      if( IS_BOARD_FLAG( board, BOARD_PRIVATE ) )
(gdb)
1809      ch_printf( ch, "%2d) %c [%-15s] %-11s %s\r\n", count, unread, pnote->date_stamp, pnote->sender ? pnote->sender : "--Error--", pnote->subject ? pnote->subject : " " );
(gdb) print count
$1 = 1
(gdb) print unread
$2 = 32 ' '
(gdb) print pnote->date_stamp
$3 = 1246064007
(gdb) print pnote->sender
$4 = 0x8e9a690 "Andril"
(gdb) print pnote->subject
$5 = 0x8f52f78 "test"


Now oddly enough, I had attempted the following before but it didn't work out quite the way I'd hoped it would heh.
char buf2[MSL], buf3[MSL]; // declared at beginning of the function

		if( IS_BOARD_FLAG( board, BOARD_PRIVATE ) )
		{
		  snprintf( buf2, MSL, pnote->sender ? pnote->sender : "--Error--" );
		  snprintf( buf3, MSL, pnote->subject ? pnote->subject : " " );

			ch_printf( ch, "%2d) %c [%-15s] %-11s %s\r\n", count, unread, pnote->date_stamp, buf2, buf3 );
		}


And here's the gdb output from printing buf2 and buf3.
(gdb) print buf2
$5 = "Andril", '\0' , "#�'\000��ゥソ-�ソ$\000\000\000\000\000\000\000zi \b\000\000\000\000\001�ゥソ�6\000yi
 \b\001\000\000\000\234�ゥソ�%\000��ソyi \b\001", '\0' , "�\026��%", '\0' , "\020�ゥソ",
'\0' , "T�ソ", '\0' , "A\000\000\000zi \bqi \b\001\000\000\000s", '\0' ,
" ", '\0' , "s$", '\0' , "xi \b", '\0' ...
(gdb) print buf3
$6 = "test", '\0' , "�P$", '\0' , "�ィソ\000\000\000\000\000\000\000\000\231\231\231\031\005",
 '\0' , "}\000\000\000\000\000\000\000�6\000\000\000\000\000\000\001\000\000��ソ�P$\000�ィソ�ィソ\n\000\000\000\000
\000\000\000\200�\000�6\000\b�ソP�ソ�ィソ\000\000\000\000\231\231\231\031\005", '\0' , "�003\000\000\000\000\000
\000�6\000\000\000\000\000\000\001\000\0008�ソ�N$\000P�ソP�ソ\n\000\000\000\000\000\000\000\200�\000�6\000h�ソ=c&\000P�"...


Now I'm pretty sure that all that extra stuff shouldn't really be there.
So yeah. You're guess is much better than mine. :)

Post is unread #7 Jun 30, 2009 6:48 pm   
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

 
Oh. You're telling it to print date_stamp as a string, but it's a number. So it's trying to follow the pointer and finding garbage there. You need to either turn date_stamp into a string or print it as an integer.

Now I'm pretty sure that all that extra stuff shouldn't really be there.

Actually it is -- note that your string is still zero-terminated. But since the buffer is of size X, it's printing out all X characters, most of which will be garbage.

Post is unread #8 Jun 30, 2009 7:36 pm   
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

 
Ahhh. Well that makes sense. And the pnote->date_stamp thing has been fixed. Now I'm just left wondering WHY I changed it to a string instead of a number... Well, I guess me being an idiot works for a reason! :)

Thanks for the help.

Post is unread #9 Jul 1, 2009 12:32 am   
Go to the top of the page
Go to the bottom of the page

Conner
Sorcerer
GroupMembers
Posts870
JoinedMay 8, 2005

 
If, for whatever reason, you really wanted it as a string, assuming there's not a standard library function for just that already, I imagine it'd be an easy enough function to write and then call. Just a thought.

Post is unread #10 Jul 1, 2009 2:33 am   
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

 
Ya, I'm thinking of adding a new char variable to the note_data structure called date, or something like that, that'll hold the actual date i.e. July 1st, 2009 10:00PM, for the creation date and time, and just replace all the places that date_stamp is sent to the player with that. I think that'd look much nicer than 1246409929, which is what one of my test notes has for the date_stamp.

Post is unread #11 Jul 1, 2009 8:35 am   
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

 
Well, I think Conner's point was that you don't need to do that: if you already have a timestamp (in seconds since the epoch presumably) there are standard library functions that will format that into a string for you. I think one is called strtimef or strftime or something like that.

Post is unread #12 Jul 1, 2009 6:58 pm   
Go to the top of the page
Go to the bottom of the page

Conner
Sorcerer
GroupMembers
Posts870
JoinedMay 8, 2005

 
Yeah, I don't recall off-hand which library function it was either but that was what I was saying. There should already be a way to do that conversion without writing your own, but even if you really wanted to write your own for whatever reason, it should be a pretty easy function to write since the time stamp is almost certainly using the standard epoch time.

Post is unread #13 Jul 1, 2009 10:31 pm   Last edited Jul 1, 2009 11:00 pm by Andril
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

 
Ya, strftime() is the function I think you're talking about. However, the ctime() function does pretty much the exact same thing, only it requires less stuff to be passed to it, and therefore is easy enough to put in that even I can do it. :)

So now, using this:
char *strtime; // --- declared up at the start of do_note_list.

// copied these two lines from comm.c so you get an actual date and stuff
// instead of a string of what looks like random numbers.
strtime = ctime (¤t_time);
strtime[strlen (strtime) - 1] = '\0'; // the ctime function adds a newline character '\n' automatically and we don't want that.
    
if( IS_BOARD_FLAG( board, BOARD_PRIVATE ) )
{
	ch_printf( ch, "%2d) %c [%-27s] %-11s %s\r\n", count, unread, strtime, pnote->sender ? pnote->sender : "--Error--",
	  pnote->subject ? pnote->subject : " " );
}
else
{
	ch_printf( ch, "%-2d) %c [ %-3d ] [%-27s] %-11s %s\r\n", count, unread, pnote->reply_count,
	  strtime, pnote->sender ? pnote->sender : "--Error--", pnote->subject ? pnote->subject : "" );
}


I get this:

Using current board in room: Immortals

--[ Notes on Immortals ]--
Num   Date                          Author      Subject
 1)   [Wed Jul  1 21:22:28 2009   ] Andril      test

There is 1 message on this board.
A * denotes unread messages.


Thanks guys!

Edit:
Meh, keep looking over my postings and seeing stuff I should probably put in after the fact....

Post is unread #14 Jul 1, 2009 11:02 pm   
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

 
(sigh) I told you I was an idiot...

strtime = ctime (¤t_time); should be strtime = ctime (&pnote->date_stamp);
(mutters under his breath)

Post is unread #15 Jul 1, 2009 11:41 pm   Last edited Jul 1, 2009 11:59 pm by Andril
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

 
And naturally I'm having another issue, this time using do_note_remove, specifically in the free_note function.

This one doesn't happen every time I erase a message, but usually the second time.

gdb has this to say:
Core was generated by `swic 4050 copyover 4'.
Program terminated with signal 6, Aborted.
#0  0x00ccc402 in __kernel_vsyscall ()
(gdb) bt
#0  0x00ccc402 in __kernel_vsyscall ()
#1  0x002408a0 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
#2  0x00242271 in abort () at abort.c:88
#3  0x002794db in __libc_message (do_abort=2, fmt=0x344884 "*** glibc detected *** %s: %s: 0x%s ***\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:170
#4  0x00281651 in _int_free (av=0x370120, mem=0x9326ac0) at malloc.c:5891
#5  0x00284cd0 in __libc_free (mem=0x9326ac0) at malloc.c:3626
#6  0x080a141b in free_note (pnote=0x9326ae0) at boards.c:359
#7  0x080a2084 in note_remove (board=0x9225530, pnote=0x9326ae0) at boards.c:560
#8  0x080a5d87 in do_note_remove (ch=0x92f7978, argument=0xbfafc27b "1") at boards.c:1943
#9  0x0812726d in interpret (ch=0x92f7978, argument=0xbfafc27b "1") at interp.c:365
#10 0x080e1109 in game_loop () at comm.c:735
#11 0x080e0623 in main (argc=4, argv=0xbfb0c354) at comm.c:417


And here's the free_note function:
void free_note( NOTE_DATA * pnote )
{
	NOTE_DATA *reply = NULL, *next_reply = NULL;

	if( pnote == NULL )
	{
		bug( "%s: NULL pnote!", __FUNCTION__ );
		return;
	}

	DISPOSE( pnote->text );
	DISPOSE( pnote->subject );
	STRFREE( pnote->to_list );
	STRFREE( pnote->sender );

	for( reply = pnote->first_reply; reply; reply = next_reply )
	{
		next_reply = reply->next;
		UNLINK( reply, pnote->first_reply, pnote->last_reply, next, prev );
		free_note( reply );
	}
	/*
	* Now dispose of the parent 
	*/
	DISPOSE( pnote );
}


Any ideas?

I'll try and step in gdb up to the point where _int_free is getting called and print out the av and mem stuff and I'll edit this post to add what I can get from that unless someone happens to post a reply before I finish.

And thanks for any help ahead of time. I really appreciate it.

Ok. After putting a break point on free_note and stepping around a bit I get a crash the second time I erase a note without either quiting or doing a copyover or something to that affect beforehand.

Here's one thing that gdb has to say about it:
*** glibc detected *** /home/mud/cbond/swic/bin/swic: double free or corruption (out): 0x0a2bf4b0 ***


Now I've noticed that if you start to write a note but abort out of it, with /a, and then start writting a new note, I get the following message:
Log: [*****] BUG: note_attach: ch->pnote already exsists!

This happens if you abort out while in the actual note text editing buffer. Could these two things be related?

Post is unread #16 Jul 2, 2009 9:08 am   Last edited Jul 2, 2009 9:08 am by David Haley
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

 
Which is line 359 in boards.c? (line numbers are always helpful so we know exactly what's going on)

If aborting the note causes the note to be deleted in the character file with a direct dispose or something, you don't want to be deleting it again. But it's hard to know without knowing which lines above are doing exactly what.

I'm not sure about the relevance of aborting a note is as the above bug appears to be triggered when removing a note, not aborting.

But clearly aborting a note causes buggy behavior as well. :)

Post is unread #17 Jul 2, 2009 2:19 pm   
Go to the top of the page
Go to the bottom of the page

Conner
Sorcerer
GroupMembers
Posts870
JoinedMay 8, 2005

 
I always get a cold shudder thinking about issues with dispose and strfree, but usually I've found that problems involving them tend to boil down to disposing or strfreeing of something more than once.

As for the possibility of the problem with aborting a message being related to the problem with deleting a message I'd have to say that they might indeed be the same problem, ultimately aborting a message is the same thing as deleting one except that when aborting the message it hadn't been saved anywhere yet, but it was still created already, no?

On the other hand, it sounds like aborting a message is only so much as throwing a bug while in gdb so I'd seriously consider worrying about the deletion issue first and then only bothering with the abortion issue if it still exists after you've dealt with the deletion issue and you're still concerned enough to bother since, while it is buggy, it's basically working. But that's just me, I hate dealing with notes and boards code anyway. :lol:

Post is unread #18 Jul 2, 2009 5:06 pm   Last edited Jul 2, 2009 5:35 pm by Andril
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

 
I knew I forgot to do something. DISPOSE( pnote->text ); is the offending line.

And I am more concerned with what's going on when you remove a note because, as you stated, the aborting issue is only an annoyance factor right now. But it's the only thing I can really give much information about at the moment so.... yeah.

Here's an example of what happens when aborting a note in two places, one is before entering the line editor and the other is while in the line editor:
Using write command
Using current board in room: Immortals.
Typing '/a' at any time will abort the note.
You begin to write a new note for the Immortals board.
To whom is this note addressed? (Default: All)             ----- Hit enter to default to All
No recipient specified. Defaulting to 'All'
To: All             From: Andril
Please enter a subject for this note:/a             ----- And abort, otherwise you drop into the line editor from here. board is private..
Aborting note...

Force:30000/30000  Align:0
-+  <$141416>+- >write
Using current board in room: Immortals.                          ---- no error messages this time...
Typing '/a' at any time will abort the note.
You begin to write a new note for the Immortals board.
To whom is this note addressed? (Default: All)
No recipient specified. Defaulting to 'All'
To: All             From: Andril
Please enter a subject for this note:test                           ---- lets set the subject to test for, well, testing purposes
To: All             From: Andril
Subject: test
Please enter the text for your message:
Begin entering your text now (/? = help /s = save /c = clear /l = list)
-----------------------------------------------------------------------
> /a                                                                              ---- but lets abort in the line editor this time

Aborting... Done.

Force:30000/30000  Align:0
-+  <$141416>+- >gr
Andril's group:
[115 Human] Andril            500/ 500 hp 1000/1000 mv

Force:30000/30000  Align:0
-+  <$141416>+- >write
Using current board in room: Immortals.
Typing '/a' at any time will abort the note.
Log: [*****] BUG: note_attach:  ch->pnote already exsists!      ---- hmm, ch->pnote not getting disposed of
You begin to write a new note for the Immortals board.
To whom is this note addressed? (Default: All)                       ---- hit enter again to accept default of All
No recipient specified. Defaulting to 'All'
To: All             From: Andril
Subject: test                                                  ---- wait a sec, I didn't get a chance to specify a subject!
Please enter the text for your message:
Begin entering your text now (/? = help /s = save /c = clear /l = list)
-----------------------------------------------------------------------
> 


So that's sort of how the whole note not being disposed of while in the line editor works.

Post is unread #19 Jul 3, 2009 7:42 pm   
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

 
Don't take the double free message so lightly: it's indicative of a real problem in your code that could under some circumstances cause crashes or memory corruption.

The easiest way to debug the problem is to run it through Valgrind, reproduce the issue, and read what Valgrind tells you. It will tell you where you freed something for the second time, and perhaps even where you freed it the first time.

Post is unread #20 Jul 3, 2009 9:27 pm   
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

 
Oh, I'm not taking it lightly, especially since that's what's causing the crashes. And I fully intend to get that fixed before really worrying about the aborting message problem. So I'm off to find me a tutorial of some sort for valgrind.

Pages:<< prev 1, 2 next >>