Re: [newbie][code] do_whois

From: Templar Viper (
Date: 01/28/03

From: Kaz <kaz@HREALMS.NET>
>  The warning is coming up because your char *buf; isn't char *buf = NULL;

Not true, see underneath:

>act.informative.c:1154: warning: `buf' might be used uninitialized in this

This means buf is used, while nothing is printed in it (buf = NULL).
Otherwise, buf might be used as NULL, which is ofcourse a bad thing

>here is my do_whois code from act.informative.c:
>if (!*argument) {
>    send_to_char(ch, "Who?\r\n");
>} else {
>    CREATE(victim, struct char_data, 1);
>    clear_char(victim);
>    if (load_char(argument, &tmp_store) > -1) {
>    store_to_char(&tmp_store, victim);
>    *buf = '\0';

This line doesn't have much use, it cleans the buffer, which should be empty

>    if (GET_LEVEL(victim) >= LVL_IMMORT)
>    sprintf(buf + strlen(buf), "%s %s %s\r\n",
>immlevels[GET_LEVEL(victim)-LVL_IMMORT], GET_NAME(victim),

Here is your problem. You try to do a strlen on the buffer, which is NULL at
that point. Result, a nice crash. Try this instead:

  if (GET_LEVEL(victim) >= LVL_IMMORT)
     sprintf(buf, "%s %s %s\r\n",
   immlevels[GET_LEVEL(victim)-LVL_IMMORT], GET_NAME(victim),

>    send_to_char(ch, buf);

I suppose you use an older version of Circlemud, or an older patch, since
send_to_char can now be used, without printing it into the buffer first.

if (GET_LEVEL(victim) >= LVL_IMMORT)
     send_to_char(ch, "%s %s %s\r\n",
   immlevels[GET_LEVEL(victim)-LVL_IMMORT], GET_NAME(victim),

If you do this, you can remove that annoying buf altogether.

I've made up this mail pretty quickly, so I might have made some errors.

Add photos to your e-mail with MSN 8. Get 2 months FREE*.

   | FAQ: |
   | Archives: |
   | Newbie List:   |

This archive was generated by hypermail 2b30 : 06/26/03 PDT