Re: [CODE] Strange Errors

From: George (greerga@circlemud.org)
Date: 01/20/99


On Thu, 21 Jan 1999, Julian Buckley wrote:

>Thu Jan 21 00:25:29 :: Saving Caniffe.
>Thu Jan 21 00:25:57 :: Saving Caniffe.
>Thu Jan 21 00:25:57 :: Saving Caniffe.
>Thu Jan 21 00:25:57 :: You say, 'My god!  It's full of stars!'

Looks like you have a log() with a bad/stale buffer.

-void basic_mud_log(const char *format, ...)
+void basic_mud_log(const char *l_file, int l_line, const char *format, ...)
{
  va_list args;
  time_t ct = time(0);
  char *time_s = asctime(localtime(&ct));

  time_s[strlen(time_s) - 1] = '\0';

-  fprintf(logfile, "%-15.15s :: ", time_s + 4);
+  fprintf(logfile, "%-15.15s %s:%d :: ", l_file, l_line, time_s + 4);

  va_start(args, format);
  vfprintf(logfile, format, args);
  va_end(args);

  fprintf(logfile, "\n");
  fflush(logfile);
}


utils.h:

-#define log            basic_mud_log
+#define log(args...)   basic_mud_log(__FILE__, __LINE__, ##args)

Don't forget to change the prototype too.

Unfortunately, you must have GCC for the above to work.

--
George Greer
greerga@circlemud.org
http://www.van.ml.org/CircleMUD/


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/15/00 PST