Need help with bug.

Posted by Toy on Wed 18 Feb 2004 02:50 PM — 5 posts, 19,839 views.

#0
Attempted to do this command "setclass warrior mtitle 54 Admin" and got this bug message:

Log: Toy: setclass warrior mtitle 54 Admin
Log: [*****] BUG: Freeing null pointer act_wiz.c:7700

So I tracked down the part of the code in error..
	DISPOSE( title_table[cl][x][0] );
	title_table[cl][x-1][0] = str_dup( argument );


Anyone know what's up?
-Toy
Canada #1
Yeah, it means that it was not initialized and not read in(not nessecarily a bad thing) and was missing the proper check. It should have been this:
	if ( title_table[cl][x][0] )
		DISPOSE( title_table[cl][x][0] );
	title_table[cl][x-1][0] = str_dup( argument );


That error is to protect your from freeing memory that doesn't exist, and that check simply checks that it is pointing somewhere.
Amended on Wed 18 Feb 2004 05:50 PM by Greven
#2
    if ( !str_cmp( arg2, "mtitle" ) )
    {
	char arg3[MAX_INPUT_LENGTH];
	int x;

	argument = one_argument( argument, arg3 );
	if ( arg3[0] == '\0' || argument[0] == '\0' )
	{
	    send_to_char( "Syntax: setclass <class> mtitle <level> <title>\n\r", ch );
	    return;
	}
	if ( (x=atoi(arg3)) < 0 || x > MAX_LEVEL )
	{
	    send_to_char( "Invalid level.\n\r", ch );
	    return;
	}
	if ( title_table[cl][x][0] )
		DISPOSE( title_table[cl][x][0] );
	title_table[cl][x-1][0] = str_dup( argument );
    }
    if ( !str_cmp( arg2, "ftitle" ) )
    {
	char arg3[MAX_INPUT_LENGTH];
	char arg4[MAX_INPUT_LENGTH];
	int x,sex;

	argument = one_argument( argument, arg3 );
	argument = one_argument( argument, arg4 );
	if ( arg3[0] == '\0' || argument[0] == '\0' )
	{
	    send_to_char( "Syntax: setclass <class> ftitle <level> <male/female> <title>\n\r", ch );
	    return;
	}
	if ( (x=atoi(arg4)) < 0 || x > MAX_LEVEL )
	{
	    send_to_char( "Invalid level.\n\r", ch );
	    return;
	}
	if ( !str_cmp( arg4, "Male") )
		sex = 0;
        else
		sex = 1;
	if ( title_table[cl][x][sex] )
	DISPOSE( title_table[cl][x][sex] );
	/* Bug fix below -Shaddai*/
	title_table[cl][x][sex] = str_dup( argument );
    }
    do_setclass( ch, "" );
}


It's strange. That cleared up the that bug, but now this happens:

Log: Toy: setclass 3 mtitle 54 admin
Syntax: setclass <class> <field> <value>
Syntax: setclass <class> create

Field being one of:
name prime weapon guild thac0 thac32
hpmin hpmax mana expbase mtitle ftitle
second, deficient affected resist suscept

No matter what I type in for mtitle and level, it just keeps show the Syntax message.

-Toy
#3
Solved it. Since "ftitle" changed both male and female titles, I removed mtitle, changed ftitle into just title,
removed this at the bottom of the code:

do_setclass( ch, "" );

And finally, I adjusted this part:

	if ( (x=atoi(arg4)) < 0 || x > MAX_LEVEL )
	{
	    send_to_char( "Invalid level.\n\r", ch );
	    return;
	}


I just changed arg4 to arg3, because because arg4 was calling to sex, not level. Didn't need to arg4's. :)

-Toy
Canada #4
It looks like the original worked, the reason you were getting the error was because there was no return after the indivudual sections, so it would fall down to the the do_setclass