From 9d0320cc8917eb39190c6e99bf7728613e47dd2a Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 18 Nov 2001 23:40:01 +0000 Subject: [PATCH] various portability improvements --- libs/gamecode/engine/pr_edict.c | 1 - libs/gamecode/engine/pr_opcode.c | 12 ++++++------ libs/util/quakefs.c | 2 +- libs/util/sizebuf.c | 4 ++-- qw/source/cl_slist.c | 11 ++++------- qw/source/net_udp.c | 7 ++++--- 6 files changed, 17 insertions(+), 20 deletions(-) diff --git a/libs/gamecode/engine/pr_edict.c b/libs/gamecode/engine/pr_edict.c index 2a45aa0ad..95e713d52 100644 --- a/libs/gamecode/engine/pr_edict.c +++ b/libs/gamecode/engine/pr_edict.c @@ -111,7 +111,6 @@ ED_ClearEdict (progs_t * pr, edict_t *e, int val) Sys_Printf("clearing reserved edict %d\n", NUM_FOR_EDICT(pr,e)); for (i=0; i < pr->progs->entityfields; i++) e->v[i].integer_var = val; - //memset (&e->v, 0, pr->progs->entityfields * 4); e->free = false; } diff --git a/libs/gamecode/engine/pr_opcode.c b/libs/gamecode/engine/pr_opcode.c index 2451a6447..7207c91a6 100644 --- a/libs/gamecode/engine/pr_opcode.c +++ b/libs/gamecode/engine/pr_opcode.c @@ -259,8 +259,8 @@ check_branch (progs_t *pr, dstatement_t *st, opcode_t *op, short offset) address += offset; if (address < 0 || address >= pr->progs->numstatements) - PR_Error (pr, "PR_Check_Opcodes: invalid branch (statement %d: %s)\n", - (int)(st - pr->pr_statements), op->opname); + PR_Error (pr, "PR_Check_Opcodes: invalid branch (statement %ld: %s)\n", + (long)(st - pr->pr_statements), op->opname); } static inline void @@ -269,9 +269,9 @@ check_global (progs_t *pr, dstatement_t *st, opcode_t *op, etype_t type, { if (type == ev_void && operand) { if (st->op != OP_RETURN && st->op != OP_DONE) //FIXME need better "not used flags" - PR_Error (pr, "PR_Check_Opcodes: non-zero global index in void operand (statement %d: %s)\n", (int)(st - pr->pr_statements), op->opname); + PR_Error (pr, "PR_Check_Opcodes: non-zero global index in void operand (statement %ld: %s)\n", (long)(st - pr->pr_statements), op->opname); } else if (operand >= pr->progs->numglobals) { - PR_Error (pr, "PR_Check_Opcodes: out of bounds global index (statement %d: %s)\n", (int)(st - pr->pr_statements), op->opname); + PR_Error (pr, "PR_Check_Opcodes: out of bounds global index (statement %ld: %s)\n", (long)(st - pr->pr_statements), op->opname); } } @@ -287,8 +287,8 @@ PR_Check_Opcodes (progs_t *pr) op = PR_Opcode (st->op); if (!op) { PR_Error (pr, - "PR_Check_Opcodes: unknown opcode %d at statement %d\n", - st->op, (int)(st - pr->pr_statements)); + "PR_Check_Opcodes: unknown opcode %d at statement %ld\n", + st->op, (long)(st - pr->pr_statements)); } switch (st->op) { case OP_IF: diff --git a/libs/util/quakefs.c b/libs/util/quakefs.c index 7ebc7d94a..583ad60ef 100644 --- a/libs/util/quakefs.c +++ b/libs/util/quakefs.c @@ -548,7 +548,7 @@ COM_LoadFile (const char *path, int usehunk) if (!buf) Sys_Error ("COM_LoadFile: not enough space for %s", path); - ((byte *) buf)[len] = 0; + buf[len] = 0; Qread (h, buf, len); Qclose (h); diff --git a/libs/util/sizebuf.c b/libs/util/sizebuf.c index d1634a20a..5dba99f2a 100644 --- a/libs/util/sizebuf.c +++ b/libs/util/sizebuf.c @@ -98,8 +98,8 @@ SZ_Print (sizebuf_t *buf, const char *data) if (!buf->cursize || buf->data[buf->cursize - 1]) // no trailing 0 - memcpy ((byte *) SZ_GetSpace (buf, len), data, len); + memcpy (SZ_GetSpace (buf, len), data, len); else // write over trailing 0 - memcpy ((byte *) SZ_GetSpace (buf, len - 1) - 1, data, len); + memcpy (SZ_GetSpace (buf, len - 1) - 1, data, len); } diff --git a/qw/source/cl_slist.c b/qw/source/cl_slist.c index 13cffed0b..3333e54e3 100644 --- a/qw/source/cl_slist.c +++ b/qw/source/cl_slist.c @@ -208,20 +208,17 @@ SL_InsB (server_entry_t *start, server_entry_t *place, char *ip, char *desc) void SL_Swap (server_entry_t *swap1, server_entry_t *swap2) { - int i; server_entry_t *next1, *next2, *prev1, *prev2; + server_entry_t temp; next1 = swap1->next; next2 = swap2->next; prev1 = swap1->prev; prev2 = swap2->prev; - for (i = 0; i < sizeof(server_entry_t); i++) - { - ((char *)swap1)[i] ^= ((char *)swap2)[i]; - ((char *)swap2)[i] ^= ((char *)swap1)[i]; - ((char *)swap1)[i] ^= ((char *)swap2)[i]; - } + temp = *swap1; + *swap1 = *swap2; + *swap2 = temp; swap1->next = next1; swap2->next = next2; diff --git a/qw/source/net_udp.c b/qw/source/net_udp.c index 9bc7e28ce..f457effd6 100644 --- a/qw/source/net_udp.c +++ b/qw/source/net_udp.c @@ -122,7 +122,7 @@ NetadrToSockadr (netadr_t *a, struct sockaddr_in *s) void SockadrToNetadr (struct sockaddr_in *s, netadr_t *a) { - *(int *) &a->ip = *(int *) &s->sin_addr; + memcpy (&a->ip, &s->sin_addr, 4); a->port = s->sin_port; } @@ -195,11 +195,12 @@ NET_StringToAdr (const char *s, netadr_t *a) } if (copy[0] >= '0' && copy[0] <= '9') { - *(int *) &sadr.sin_addr = inet_addr (copy); + int addr = inet_addr (copy); + memcpy (&sadr.sin_addr, &addr, 4); } else { if (!(h = gethostbyname (copy))) return 0; - *(int *) &sadr.sin_addr = *(int *) h->h_addr_list[0]; + memcpy (&sadr.sin_addr, h->h_addr_list[0], 4); } SockadrToNetadr (&sadr, a);