buffer problems

From: Kras Kresh (kras_kresh@hotmail.com)
Date: 08/16/02


I seem to be having a color processing problem. I am unable to fix it.
Sometimes, the MUD decides to show very weird things. Example:

When someone loots a few dozen items:
You get <item x>.
You get <item y>.
You get <item z>.
You get <item z>You getYou get <half of item z>. Youblahblahlah
etc.

And no, the code for the items are perfectly fine. This points to a buffer
problem.
Sometimes... logs
WARNING: write_to_descriptor: socket write would block, about to close.
and the mud will crash soon after.

I'll give a short code of what I have.

/* This should be equal to LARGE_BUFSIZE in structs.h */
#define BUFSPACE        (12 * 1024 - 32 - 96)
/* LARGE_BUFSIZE =   MAX_SOCK_BUF      (12 * 1024)
                   - GARBAGE_SPACE     (32)
                   - MAX_PROMPT_LENGTH (96)

  File does not #include "structs.h", but the numbers are correct.
*/

#define BUFSIZE         (BUFSPACE - 1)
char out_buf[BUFSPACE], insert_text[BUFSPACE];

void proc_color(char *inbuf, int color_lvl)
{
  declarations and stuff

  *out_buf = '\0';

  while (inbuf[inpos] != '\0') {
    if (is a color scheme) {
      modify insert_text, but always ends with '\0'
      inpos moves forward by length of color scheme
      temp = strlen(insert_text);

      if (strlen(out_buf) + temp < BUFSIZE) {
        strcpy(out_buf + outpos, insert_text);
/* The strcpy here isn't the problem is it? */
        outpos += temp;
      }
      else {
        strcpy(out_buf + BUFSIZE - 15, "**OvERFLOW**\r\n");
        outpos = BUFSIZE;
        break;
      }
    } else
      if (outpos < BUFSIZE)
        out_buf[outpos++] = inbuf[inpos++];
      else {
        strcpy(out_buf + BUFSIZE - 15, "**OVERFLoW**\r\n");
        break;
      }
  } /* while */

  out_buf[outpos] = '\0';

  strcpy(inbuf, out_buf);
/* The strcpy here isn't the problem is it? */
}

Is the problem that sizeof(out_buf) is greater than sizeof(inbuf)?

_________________________________________________________________
Join the world’s largest e-mail service with MSN Hotmail.
http://www.hotmail.com

--
   +---------------------------------------------------------------+
   | 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