[util] Make sizebuf and msg sizes unisgned

And clean up the mess.
This commit is contained in:
Bill Currie 2021-04-04 15:53:53 +09:00
parent 9a2f82bbc6
commit 972b0f8a70
14 changed files with 54 additions and 50 deletions

View file

@ -41,7 +41,7 @@ void MSG_WriteLong (sizebuf_t *sb, int c);
void MSG_WriteLongBE (sizebuf_t *sb, int c);
void MSG_WriteFloat (sizebuf_t *sb, float f);
void MSG_WriteString (sizebuf_t *sb, const char *s);
void MSG_WriteBytes (sizebuf_t *sb, const void *buf, int len);
void MSG_WriteBytes (sizebuf_t *sb, const void *buf, unsigned len);
void MSG_WriteCoord (sizebuf_t *sb, float coord);
void MSG_WriteCoordV (sizebuf_t *sb, const vec3_t coord);
void MSG_WriteCoordAngleV (sizebuf_t *sb, const vec3_t coord,
@ -53,11 +53,11 @@ void MSG_WriteAngle16V (sizebuf_t *sb, const vec3_t angle);
void MSG_WriteUTF8 (sizebuf_t *sb, unsigned utf8);
typedef struct msg_s {
int readcount;
qboolean badread; // set if a read goes beyond end of message
sizebuf_t *message;
size_t badread_string_size;
char *badread_string;
unsigned readcount;
qboolean badread; // set if a read goes beyond end of message
sizebuf_t *message;
size_t badread_string_size;
char *badread_string;
} qmsg_t;
/** Reset the message read status.
@ -75,7 +75,7 @@ void MSG_BeginReading (qmsg_t *msg);
\param msg The message to check.
\return The number of bytes that have been read.
*/
int MSG_GetReadCount(qmsg_t *msg) __attribute__((pure));
unsigned MSG_GetReadCount(qmsg_t *msg) __attribute__((pure));
/** Read a single byte from the message.
@ -175,7 +175,7 @@ const char *MSG_ReadString (qmsg_t *msg);
\param len The number of bytes to read.
\return The number of bytes read from the message.
*/
int MSG_ReadBytes (qmsg_t *msg, void *buf, int len);
int MSG_ReadBytes (qmsg_t *msg, void *buf, unsigned len);
/** Read a little-endian 16-bit fixed point (13.3) coordinate value from the
message.

View file

@ -37,18 +37,18 @@
typedef struct sizebuf_s
{
qboolean allowoverflow; // if false, do a Sys_Error
qboolean overflowed; // set to true if the buffer size failed
byte *data;
int maxsize;
int cursize;
qboolean allowoverflow; // if false, do a Sys_Error
qboolean overflowed; // set to true if the buffer size failed
byte *data;
unsigned maxsize;
unsigned cursize;
} sizebuf_t;
void SZ_Alloc (sizebuf_t *buf, int maxsize);
void SZ_Alloc (sizebuf_t *buf, unsigned maxsize);
void SZ_Free (sizebuf_t *buf);
void SZ_Clear (sizebuf_t *buf);
void *SZ_GetSpace (sizebuf_t *buf, int length);
void SZ_Write (sizebuf_t *buf, const void *data, int length);
void *SZ_GetSpace (sizebuf_t *buf, unsigned length);
void SZ_Write (sizebuf_t *buf, const void *data, unsigned length);
void SZ_Print (sizebuf_t *buf, const char *data); // strcats onto the sizebuf
void SZ_Dump (sizebuf_t *buf);

View file

@ -317,7 +317,7 @@ void Netchan_Init_Cvars (void);
\param length The size of the unreliable packet.
\param data The data of the unreliable packet.
*/
void Netchan_Transmit (netchan_t *chan, int length, byte *data);
void Netchan_Transmit (netchan_t *chan, unsigned length, byte *data);
/** Send an out-of-band packet.
@ -325,7 +325,7 @@ void Netchan_Transmit (netchan_t *chan, int length, byte *data);
\param length The length of the data to be sent.
\param data The data to be sent.
*/
void Netchan_OutOfBand (netadr_t adr, int length, byte *data);
void Netchan_OutOfBand (netadr_t adr, unsigned length, byte *data);
/** Send a formatted string as an out-of-band packet.
\param adr The address to which the data will be sent.

View file

@ -43,10 +43,10 @@ typedef struct backbuf_s {
const char *name;
} backbuf_t;
int MSG_ReliableCheckSize (backbuf_t *rel, int maxsize, int minsize) __attribute__((pure));
sizebuf_t *MSG_ReliableCheckBlock(backbuf_t *rel, int maxsize);
int MSG_ReliableCheckSize (backbuf_t *rel, unsigned maxsize, unsigned minsize) __attribute__((pure));
sizebuf_t *MSG_ReliableCheckBlock(backbuf_t *rel, unsigned maxsize);
void MSG_Reliable_FinishWrite(backbuf_t *rel);
sizebuf_t *MSG_ReliableWrite_Begin(backbuf_t *rel, int c, int maxsize);
sizebuf_t *MSG_ReliableWrite_Begin(backbuf_t *rel, int c, unsigned maxsize);
void MSG_ReliableWrite_Angle(backbuf_t *rel, float f);
void MSG_ReliableWrite_Angle16(backbuf_t *rel, float f);
void MSG_ReliableWrite_Byte(backbuf_t *rel, int c);
@ -56,7 +56,7 @@ void MSG_ReliableWrite_Coord(backbuf_t *rel, float f);
void MSG_ReliableWrite_Long(backbuf_t *rel, int c);
void MSG_ReliableWrite_Short(backbuf_t *rel, int c);
void MSG_ReliableWrite_String(backbuf_t *rel, const char *s);
void MSG_ReliableWrite_SZ(backbuf_t *rel, const void *data, int len);
void MSG_ReliableWrite_SZ(backbuf_t *rel, const void *data, unsigned len);
void MSG_ReliableWrite_AngleV(backbuf_t *rel, const vec3_t v);
void MSG_ReliableWrite_CoordV(backbuf_t *rel, const vec3_t v);
void MSG_Reliable_Send (backbuf_t *rel);

View file

@ -92,7 +92,7 @@ Netchan_Init_Cvars (void)
Sends an out-of-band datagram
*/
void
Netchan_OutOfBand (netadr_t adr, int length, byte * data)
Netchan_OutOfBand (netadr_t adr, unsigned length, byte * data)
{
byte send_buf[MAX_MSGLEN + PACKET_HEADER];
sizebuf_t send;
@ -185,7 +185,7 @@ Netchan_CanReliable (netchan_t *chan)
}
void
Netchan_Transmit (netchan_t *chan, int length, byte *data)
Netchan_Transmit (netchan_t *chan, unsigned length, byte *data)
{
byte send_buf[MAX_MSGLEN + PACKET_HEADER];
int i;

View file

@ -59,7 +59,7 @@ PushBackbuf (backbuf_t *rel)
}
int
MSG_ReliableCheckSize (backbuf_t *rel, int maxsize, int minsize)
MSG_ReliableCheckSize (backbuf_t *rel, unsigned maxsize, unsigned minsize)
{
sizebuf_t *msg = &rel->netchan->message;
@ -80,7 +80,7 @@ MSG_ReliableCheckSize (backbuf_t *rel, int maxsize, int minsize)
// check to see if client block will fit, if not, rotate buffers
sizebuf_t *
MSG_ReliableCheckBlock (backbuf_t *rel, int maxsize)
MSG_ReliableCheckBlock (backbuf_t *rel, unsigned maxsize)
{
sizebuf_t *msg = &rel->netchan->message;
@ -108,7 +108,7 @@ MSG_ReliableCheckBlock (backbuf_t *rel, int maxsize)
// begin a client block, estimated maximum size
sizebuf_t *
MSG_ReliableWrite_Begin (backbuf_t *rel, int c, int maxsize)
MSG_ReliableWrite_Begin (backbuf_t *rel, int c, unsigned maxsize)
{
sizebuf_t *msg;
msg = MSG_ReliableCheckBlock (rel, maxsize);
@ -226,7 +226,7 @@ MSG_ReliableWrite_String (backbuf_t *rel, const char *s)
}
void
MSG_ReliableWrite_SZ (backbuf_t *rel, const void *data, int len)
MSG_ReliableWrite_SZ (backbuf_t *rel, const void *data, unsigned len)
{
if (rel->num_backbuf) {
SZ_Write (&rel->backbuf, data, len);

View file

@ -126,7 +126,7 @@ MSG_WriteString (sizebuf_t *sb, const char *s)
}
VISIBLE void
MSG_WriteBytes (sizebuf_t *sb, const void *buf, int len)
MSG_WriteBytes (sizebuf_t *sb, const void *buf, unsigned len)
{
SZ_Write (sb, buf, len);
}
@ -253,7 +253,7 @@ MSG_BeginReading (qmsg_t *msg)
msg->badread = false;
}
VISIBLE int
VISIBLE unsigned
MSG_GetReadCount (qmsg_t *msg)
{
return msg->readcount;
@ -403,7 +403,7 @@ MSG_ReadString (qmsg_t *msg)
}
VISIBLE int
MSG_ReadBytes (qmsg_t *msg, void *buf, int len)
MSG_ReadBytes (qmsg_t *msg, void *buf, unsigned len)
{
if (msg->badread || len > msg->message->cursize - msg->readcount) {
msg->badread = true;
@ -474,7 +474,8 @@ VISIBLE int
MSG_ReadUTF8 (qmsg_t *msg)
{
byte *buf, *start, c;
int val = 0, count;
int val = 0;
unsigned count;
if (msg->badread || msg->message->cursize == msg->readcount) {
msg->badread = true;

View file

@ -41,7 +41,7 @@
VISIBLE void
SZ_Alloc (sizebuf_t *buf, int maxsize)
SZ_Alloc (sizebuf_t *buf, unsigned maxsize)
{
if (maxsize < 256)
maxsize = 256;
@ -58,7 +58,7 @@ SZ_Clear (sizebuf_t *buf)
}
VISIBLE void *
SZ_GetSpace (sizebuf_t *buf, int length)
SZ_GetSpace (sizebuf_t *buf, unsigned length)
{
void *data;
@ -83,7 +83,7 @@ getspace:
}
VISIBLE void
SZ_Write (sizebuf_t *buf, const void *data, int length)
SZ_Write (sizebuf_t *buf, const void *data, unsigned length)
{
memcpy (SZ_GetSpace (buf, length), data, length);
}
@ -91,7 +91,7 @@ SZ_Write (sizebuf_t *buf, const void *data, int length)
VISIBLE void
SZ_Print (sizebuf_t *buf, const char *data)
{
int len;
unsigned len;
len = strlen (data) + 1;
if (buf->cursize && !buf->data[buf->cursize - 1])
@ -103,7 +103,7 @@ SZ_Print (sizebuf_t *buf, const char *data)
VISIBLE void
SZ_Dump (sizebuf_t *buf)
{
int i;
unsigned i;
char chars[17], c;
chars[16] = 0;

View file

@ -174,7 +174,8 @@ check_next_demopacket (void)
static int
read_demopacket (void)
{
int i, r;
int i;
unsigned r;
float f;
Qread (cls.demofile, &net_message->message->cursize, 4);

View file

@ -124,7 +124,7 @@ server_compare (const void *a, const void *b)
}
static void
setup_sub_message (qmsg_t *msg, qmsg_t *sub, sizebuf_t *buf, int len)
setup_sub_message (qmsg_t *msg, qmsg_t *sub, sizebuf_t *buf, unsigned len)
{
memset (sub, 0, sizeof (qmsg_t));
memset (buf, 0, sizeof (sizebuf_t));
@ -274,7 +274,7 @@ server_handler (connection_t *con, void *object)
if (!Netchan_Process (&sv->netchan))
return;
if (0) {
int i;
unsigned i;
for (i = 0; i < net_message->message->cursize; i++)
qtv_printf ("%c%02x", (i % 16) ? ' ' : '\n',

View file

@ -41,7 +41,7 @@ recorder_t *SVR_AddUser (void (*writer)(void *, struct sizebuf_s *, int),
void (*finish)(void *, struct sizebuf_s *),
int demo, void *user);
void SVR_RemoveUser (recorder_t *r);
struct sizebuf_s *SVR_WriteBegin (byte type, int to, int size);
struct sizebuf_s *SVR_WriteBegin (byte type, int to, unsigned size);
struct sizebuf_s *SVR_Datagram (void) __attribute__((const));
void SVR_ForceFrame (void);
void SVR_Pause (recorder_t *r);

View file

@ -271,7 +271,7 @@ check_next_demopacket (void)
static int
read_demopacket (void)
{
int r;
unsigned r;
Qread (cls.demofile, &net_message->message->cursize, 4);
net_message->message->cursize =

View file

@ -1013,8 +1013,10 @@ CL_ReadPackets (void)
{
while (CL_GetMessage ()) {
if (net_message->message->cursize == -1)
// non-packet set up by the demo reader
if ((int) net_message->message->cursize == -1) {
continue;
}
if (cls.demoplayback && net_packetlog->int_val)
Log_Incoming_Packet (net_message->message->data,

View file

@ -56,8 +56,8 @@
typedef struct dbuffer_s {
byte *data;
int start, end, last;
int maxsize;
unsigned start, end, last;
unsigned maxsize;
} dbuffer_t;
typedef struct header_s {
@ -70,7 +70,7 @@ typedef struct header_s {
typedef struct demobuf_s {
sizebuf_t sz;
int bufsize;
unsigned bufsize;
header_t *h;
} demobuf_t;
@ -200,9 +200,9 @@ write_msg (sizebuf_t *msg, int type, int to, float time, sizebuf_t *dst)
static void
write_to_msg (int type, int to, float time, sizebuf_t *dst)
{
int pos = 0;
unsigned pos = 0;
header_t *p;
int size;
unsigned size;
sizebuf_t msg;
p = (header_t *) rec.dbuf->sz.data;
@ -256,7 +256,7 @@ static void
set_buf (byte type, int to)
{
header_t *p;
int pos = 0;
unsigned pos = 0;
p = (header_t *) rec.dbuf->sz.data;
@ -464,7 +464,7 @@ write_packet (void)
}
sizebuf_t *
SVR_WriteBegin (byte type, int to, int size)
SVR_WriteBegin (byte type, int to, unsigned size)
{
byte *p;
qboolean move = false;