The reason you are probably having the random messages is because 
'buf' is unitialized.


This code will never get executed:

if ( buf[0] == '\0' )
       strcpy( buf, "No posts.");

Thus when there are no notes, you are returning:
return str_dup(buf);

which is a dup on uninitialized data.

Simple fix:

buf[0]=0;
at the start.

> -----Original Message-----
> From: Matt Foltz [mailto:[EMAIL PROTECTED] 
> Sent: Saturday, July 05, 2003 2:29 PM
> To: [email protected]
> Subject: Last post function bug
> 
> 
> I redid my unread command so it listed the author of the last 
> note.  I know it's probably a little sloppy but here is the
> function:
> 
> char *last_post(CHAR_DATA *ch, NOTE_DATA *spool)
> {
>    char buf[MAX_STRING_LENGTH];
>    NOTE_DATA *pnote;
> 
>    for (pnote = spool; pnote != NULL; pnote = pnote->next )
>       if (is_note_to( ch, pnote ) )
>          strcpy( buf, pnote->sender );
> 
>    if ( buf[0] == '\0' )
>       strcpy( buf, "No posts.");
> 
>    return str_dup(buf);
> }
> 
> Now the problem is that when you type unread, you get random 
> strings in place of the author's name.  I've seen strings 
> like the last person to login, to "1m's magic misses you."  
> It's really bizarre.  What am I doing wrong?
> 
> =====
> -Matt Foltz
> [Neoterra MUD] telnet://neoterra.is-a-geek.com:4000
> [Car Audio Resources homepage] http://www.car-audio.net
> 
> __________________________________
> Do you Yahoo!?
> SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com
> 
> -- 
> ROM mailing list
> [email protected]
> http://www.rom.org/cgi-bin/mailman/listinfo/rom
> 

Reply via email to