Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, Google, Yandex

Members: 0
Guests: 9
Stats
Files
Topics
Posts
Members
Newest Member
481
3,734
19,366
618
Micheal64X
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » Coding » A bit of code help :)
Forum Rules | Mark all | Recent Posts

A bit of code help :)
< Newer Topic :: Older Topic > Brain is fried. .. *clunk*

Pages:<< prev 1 next >>
Post is unread #1 May 7, 2003, 9:57 pm   Last edited Nov 24, 2007, 4:33 pm by Samson
Go to the top of the page
Go to the bottom of the page

Xorith
The Null Value
GroupAFKMud Team
Posts254
JoinedFeb 23, 2003

Ok, since two (or more) heads are better than one... can anyone spot the segfault here? ;)

void do_logins( CHAR_DATA *ch )
{
	SYSTEM_DATA sys;
	int x;
	char buf[MSL];

	for( x = 0; x < MAX_CONNHISTORY; x++ )
	{
		if ( sys.connhistory[x] == NULL )
		{
			send_to_char( "No Data.\r\n", ch );
			break;
		}
		sprintf( buf, sys.connhistory[x] );
		send_to_char( buf, ch );
	}
	return;
}


What: I've copied Samson's lead with the channel histories and I've altered the code to keep track of logins. connhistory is a part of SYSTEM_DATA, which is declared with a MAX_CONNHISTORY of 20.

Now, the update_connhistory code seems to work alright, as it doesn't segfault when people connect or quit (I have it setup to do the updates then for now). When I try to use this command though, it does.

I've got the crash data too, you can view it at: http://neomud.kyndig.com/do_logins_crash.txt

I'll give more info upon request.

This has just burnt my brain tonight. Hope someone can smack me and show me the tiny mistake I've made!
       
Post is unread #2 May 8, 2003, 6:02 am   Last edited Nov 24, 2007, 4:33 pm by Samson
Go to the top of the page
Go to the bottom of the page

Samson
Black Hand
GroupAdministrators
Posts3,643
JoinedJan 1, 2002

 sprintf( buf, sys.connhistory[x] );
send_to_char( buf, ch );


These 2 lines can be consolidated into this:

ch_printf( ch, "%s\r\n", sys.connhistory[x] );


Part of your problem may have been using sprintf badly, not sure. But give this a shot and see what you get.
       
Post is unread #3 May 8, 2003, 11:46 am
Go to the top of the page
Go to the bottom of the page

Xorith
The Null Value
GroupAFKMud Team
Posts254
JoinedFeb 23, 2003

Well, I tried what you suggested and it still segfaults.

Curious...

Well I just got word from my host that my code port reached max CPU usage.. (erk).

I obviously screwed something up deeper than the command, and I'm at work currently. The only thing I can think is my choice for where to put the array. I put it in the SYSTEM_DATA Struct, as a

char *chanhistory[MAX_CONNHISTORY]

MAX_CONNHISTORY is defined in neocode.h as 20.

Mud.h includes that file, and I don't get any errors upon compile.

The updating goes almost identical to how your channel history goes. The only thing I had to modify was variable names and checks for invis and level.

I'll look things over again when I get home, but this just proves that I'm not as good as I thought I was. I feel rusty! Ick!

Thanks
       
Post is unread #4 May 8, 2003, 11:53 am   Last edited Nov 24, 2007, 4:33 pm by Samson
Go to the top of the page
Go to the bottom of the page

Guest - (Unregistered)

I've got the crash data too, you can view it at: http://neomud.kyndig.com/do_logins_crash.txt


Firstly.. that link gives a nice "Forbbiden" message so we can't see the text file

Ok, since two (or more) heads are better than one... can anyone spot the segfault here? ;)
void do_logins( CHAR_DATA *ch )
{
SYSTEM_DATA sys;
int x;
char buf[MSL];
for( x = 0; x < MAX_CONNHISTORY; x++ )
{
if ( sys.connhistory[x] == NULL )
{
send_to_char( "No Data.\r\n", ch );
break;
}
sprintf( buf, sys.connhistory[x] );
send_to_char( buf, ch );
}
return;
}


And you are initalizing all the sys.conhistory[] entries to NULL before you ever use it don't you? As otherwise it will start with some random value prolly, which isn't NULL (which is classically 0x0) and it will attempt a sprintf() with it, being an invalid pointer when it accesses it, code dumping follows

Now, the update_connhistory code seems to work alright, as it doesn't segfault when people connect or quit (I have it setup to do the updates then for now). When I try to use this command though, it does.


You would never see a problem if you are always comparing against NULL as you are simply shifting around a bunch of invalid pointers, but unless you access those pointers it will never know... and thus when you try to view the invalid pointers... kaboom

All I can think of right this min...
       
Post is unread #5 May 8, 2003, 12:26 pm
Go to the top of the page
Go to the bottom of the page

Xorith
The Null Value
GroupAFKMud Team
Posts254
JoinedFeb 23, 2003

Ah, link should be fixed. Sorry... and hrm... I don't think I am doing that. In fact, I completely didn't even think about that.

I'll take a look when I get home. Thanks
       
Pages:<< prev 1 next >>