still note problem...

Posted by Ithildin on Tue 11 May 2004 04:29 AM — 3 posts, 15,410 views.

USA #0
ok, this is frustrating me to no end. i've tried to mess with this, i've tried to just set it down and think about it, i've tried to not think about it. but i can't seem to get what's goin on here. it sometimes crashes on note send when it's the first note, but always crashes on note remove 0. i can remove any other note except note 0. here's the code:


void note_remove( CHAR_DATA *ch, NOTE_DATA *pnote )
{
    FILE      *fp;
    NOTE_DATA *prev;
    char      *to_list;
    char       to_new [ MAX_INPUT_LENGTH ];
    char       to_one [ MAX_INPUT_LENGTH ];

    /*
     * Build a new to_list.
     * Strip out this recipient.
     */
    to_new[0]	= '\0';
    to_list	= pnote->to_list;
    while ( *to_list != '\0' )
    {
	to_list	= one_argument( to_list, to_one );
	if ( to_one[0] != '\0' && str_cmp( ch->name, to_one ) )
	{
	    strcat( to_new, " "    );
	    strcat( to_new, to_one );
	}
    }

    /*
     * Just a simple recipient removal?
     */
    if ( str_cmp( ch->name, pnote->sender ) && to_new[0] != '\0' )
    {
	STRFREE( pnote->to_list );
	pnote->to_list = str_dup( to_new + 1 );
	return;
    }

    /*
     * Remove note from linked list.
     */
    if ( pnote == note_list )
    {
	note_list = pnote->next;
    }
    else
    {
	for ( prev = note_list; prev; prev = prev->next )
	{
	    if ( prev->next == pnote )
		break;
	}

	if ( !prev )
	{
	    bug( "Note_remove: pnote not found.", 0 );
	    return;
	}

	prev->next = pnote->next;
    }

    STRFREE( pnote->text    );
    STRFREE( pnote->subject );
    STRFREE( pnote->to_list );
    STRFREE( pnote->date    );
    STRFREE( pnote->sender  );
    pnote->next	= note_free;
    note_free	= pnote;

    /*
     * Rewrite entire list.
     */
    fclose( fpReserve );
    if ( !( fp = fopen( NOTE_FILE, "w" ) ) )
    {
	perror( NOTE_FILE );
    }
    else
    {
	for ( pnote = note_list; pnote; pnote = pnote->next )
	{
	    fprintf( fp, "Sender  %s~\n", pnote->sender     );
	    fprintf( fp, "Date    %s~\n", pnote->date       );
	    fprintf( fp, "Stamp   %ld\n", (unsigned long)pnote->date_stamp );
	    fprintf( fp, "To      %s~\n", pnote->to_list    );
	    fprintf( fp, "Subject %s~\n", pnote->subject    );
	    fprintf( fp, "Text\n%s~\n\n", pnote->text       );
	}
	fclose( fp );
    }
    fpReserve = fopen( NULL_FILE, "r" );
    return;
}



and here is the remove in do_note:


if ( !str_cmp( arg, "remove" ) )
    {
	if ( !is_number( argument ) )
	{
	    send_to_char( "Note remove which number?\n\r", ch );
	    return;
	}

	anum = atoi( argument );
	vnum = 0;
	for ( pnote = note_list; pnote; pnote = pnote->next )
	{
	    if ( is_note_to( ch, pnote ) && vnum++ == anum )
	    {
		note_remove( ch, pnote );
		send_to_char( "Ok.\n\r", ch );
		return;
	    }
	}


does anyone see anything? i just can't seem to figure this out
Canada #1
As to which line its crashing on, can you paste a back trace from gdb while running it inside? Should give you exactly where you need to look. However, this:
	STRFREE( pnote->to_list );
	pnote->to_list = str_dup( to_new + 1 );
Is quite wrong. This MAY be the problem, that if your removing more than one note, pnote->to_list will not be the proper type when its called at "STRFREE( pnote->to_list );". If you change it to STRALLOC instead of str_dup, it may clear up a few problems. Can't see anything when I'm quite this tired, but that is definately a problem.
USA #2

(gdb) bt
#0  0x610ab081 in random () from /usr/bin/cygwin1.dll
#1  0x610aae17 in random () from /usr/bin/cygwin1.dll
#2  0x61054ca6 in localtime_r () from /usr/bin/cygwin1.dll
#3  0x610e26ba in wmemset () from /usr/bin/cygwin1.dll
#4  0x610e1d3a in wmemset () from /usr/bin/cygwin1.dll
#5  0x610cf303 in wmemset () from /usr/bin/cygwin1.dll
#6  0x610cf1f4 in wmemset () from /usr/bin/cygwin1.dll
#7  0x610d2e9f in wmemset () from /usr/bin/cygwin1.dll
#8  0x61086211 in cygwin1!aclcheck () from /usr/bin/cygwin1.dll
#9  0x004829ff in do_note (ch=0x1038fa88, argument=0x22ea2c "0")
    at boards.c:483
#10 0x004faecd in interpret (ch=0x1038fa88, argument=0x22ea25 "remove 0")
    at interp.c:547
#11 0x004b5087 in game_loop () at comm.c:643
#12 0x004b4284 in main (argc=1, argv=0x10010da0) at comm.c:289


i've shown some stuff in my old note post. you can take a gander at that as well. i just started a new post to start fresh over.