[NEWBIE][CODE] Error writing to file ... :(

From: Justin Adler (spam@WORLD-DOMINATION.COM.AU)
Date: 06/27/02


Hello Guru's.

  I have the following code, and it is core dumping, and i do not know
why :(


{utils.c}
void append_to_file (char *line, char *filename) {
...
fprintf (file, line);         // ***** CRASH HERE
fclose (file);
return;
...


gdb reports the following info...
line=0x8213d00 "[Orc] OOC:  %n %n\n", filename=0x81353af "../log/ooc"
-or-
line=0x81c5bd0 "[Riseth] OOC:  nope i'm 100% new and 95% naive...\n",
    filename=0x80fda2d "../log/ooc"

after extensive testing, i've found the code crashes when the following
string is INCLUDED in the variable 'line' => %n %n

**** Any other strings seem to work FINE. ****


it's really weird ... i just don't get it:(  everything else is
fprintf'ing to file ....

also, i think this is STOCK CODE from around bp11 or 13, but when i
checked bp21 i couldn't grep it.

Thank you in advance for any help forthcoming :)

-Pure Kr0me-

References
^^^^^^^^^^
Full Function.

{utils.c}
void append_to_file (char *line, char *filename)
{
  FILE *file;
  char buf[256];

  if (!(file = fopen (filename, "a"))) {
    sprintf (buf, "SYSERR: Can't open file %s to append,
append_to_file.\r\n", filename);
    mudlog (buf, BRF, LVL_GRGOD, TRUE);
    return;
  }

  fprintf (file, line);
  fclose (file);
  return;

}

--
   +---------------------------------------------------------------+
   | 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/25/03 PDT