[crossfire] SockList buffer size difference in server/client. Bug?

Kevin R. Bulgrien kbulgrien at att.net
Thu Sep 30 22:05:24 CDT 2010


server/trunk/include/shared/newclient.h:

/**
 * Maximum size of a packet the client expects to get.  Using a buffer of this
 * size allows the client to avoid constant allocation and deallocation of the
 * same buffer over and over again (at the cost of using extra memory).  This
 * also makes the code simpler.  The size is big enough to receive any valid
 * packet: 2 bytes for length, 65535 for maximum packet size, 1 for appended a
 * trailing null character.
 */
#define MAXSOCKBUF (2+65535+1)

  .  .  .

/**
 * Contains the base information we use to make up a packet we want to send.
 */
typedef struct SockList {
#ifdef CLIENT_TYPES_H                       /* Used by the client */
    int len;
    unsigned char *buf;
#else                                       /* Used by the server */
    size_t len;
    unsigned char buf[2+65536UL+1]; /* 2=length, 65536=content, 1=trailing      
NUL */
#endif
} SockList;

Is use of 65536 in server vs 65535 in the client a bug?

In client, the buffer is malloc'd in main().  It almost seems that it could
just as well be statically allocated there too... doesn't seem like there
is much point in the ifdef here.

Kevin



More information about the crossfire mailing list