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
>function
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
(trademarked).
>here is my do_whois code from act.informative.c:
>ACMD(do_whois)
>{
>[..]
>
>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
anyhow.
> if (GET_LEVEL(victim) >= LVL_IMMORT)
> sprintf(buf + strlen(buf), "%s %s %s\r\n",
>immlevels[GET_LEVEL(victim)-LVL_IMMORT], GET_NAME(victim),
>GET_TITLE(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),
GET_TITLE(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.
Try:
if (GET_LEVEL(victim) >= LVL_IMMORT)
send_to_char(ch, "%s %s %s\r\n",
immlevels[GET_LEVEL(victim)-LVL_IMMORT], GET_NAME(victim),
GET_TITLE(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*.
http://join.msn.com/?page=features/featuredemail
--
+---------------------------------------------------------------+
| FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
| Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
| Newbie List: http://groups.yahoo.com/group/circle-newbies/ |
+---------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 06/26/03 PDT