Change pointer_t to unsigned and clean up the mess.

It doesn't make sense to have negative pointers. The size of the commit is
from enabling gcc's -Wtype-limits warning and cleaning up that mess too.
This commit is contained in:
Bill Currie 2012-12-21 21:53:13 +09:00
parent 7701393bd4
commit 6eb6b6c0ba
25 changed files with 55 additions and 57 deletions

View file

@ -190,6 +190,7 @@ QF_CC_OPTION(-Wsign-compare)
if test $CC_MAJ -gt 4 -o $CC_MAJ -eq 4 -a $CC_MIN -ge 5; then
QF_CC_OPTION(-Wlogical-op)
fi
QF_CC_OPTION(-Wtype-limits)
QF_CC_OPTION_TEST([-fvisibility=hidden], [VISIBILITY=-fvisibility=hidden])
dnl QuakeForge uses lots of BCPL-style (//) comments, which can cause problems

View file

@ -29,7 +29,7 @@ typedef int32_t pr_int_t;
typedef uint32_t pr_uint_t;
typedef pr_int_t func_t;
typedef pr_int_t string_t;
typedef pr_int_t pointer_t;
typedef pr_uint_t pointer_t;
typedef enum {
ev_void,

View file

@ -206,7 +206,7 @@ int PR_RunLoadFuncs (progs_t *pr);
*/
int PR_Check_Opcodes (progs_t *pr);
void PR_BoundsCheckSize (progs_t *pr, int addr, unsigned size);
void PR_BoundsCheckSize (progs_t *pr, pointer_t addr, unsigned size);
void PR_BoundsCheck (progs_t *pr, int addr, etype_t type);
//@}
@ -1577,7 +1577,7 @@ struct progs_s {
ddef_t *pr_fielddefs;
dstatement_t *pr_statements;
pr_type_t *pr_globals;
int globals_size;
unsigned globals_size;
//@}
/// \name parameter block
@ -1630,8 +1630,8 @@ struct progs_s {
/// \name obj info
//@{
int selector_index;
int selector_index_max;
unsigned selector_index;
unsigned selector_index_max;
struct obj_list_s **selector_sels;
string_t *selector_names;
struct hashtab_s *selector_hash;

View file

@ -478,7 +478,7 @@ SND_SetPaint (sfxbuffer_t *sc)
};
wavinfo_t *info = sc->sfx->wavinfo (sc->sfx);
if (info->channels < 0 || info->channels > 8)
if (info->channels > 8)
Sys_Error ("illegal channel count %d", info->channels);
sc->paint = painters[info->channels];
}

View file

@ -395,8 +395,7 @@ PR_Get_Lineno_Addr (progs_t *pr, pr_lineno_t *lineno)
if (lineno->line)
return lineno->fa.addr;
if (lineno->fa.func >= 0
&& lineno->fa.func < pr->debug->num_auxfunctions) {
if (lineno->fa.func < pr->debug->num_auxfunctions) {
f = &pr->auxfunctions[lineno->fa.func];
return pr->pr_functions[f->function].first_statement;
}
@ -701,7 +700,7 @@ def_string (progs_t *pr, pr_int_t ofs, dstring_t *dstr)
}
static const char *
global_string (progs_t *pr, pr_int_t ofs, etype_t type, int contents)
global_string (progs_t *pr, pointer_t ofs, etype_t type, int contents)
{
static dstring_t *line = NULL;
ddef_t *def = NULL;

View file

@ -255,9 +255,9 @@ PR_LeaveFunction (progs_t *pr)
}
VISIBLE void
PR_BoundsCheckSize (progs_t *pr, int addr, unsigned size)
PR_BoundsCheckSize (progs_t *pr, pointer_t addr, unsigned size)
{
if (addr < 0 || addr >= pr->globals_size
if (addr >= pr->globals_size
|| size > (unsigned) (pr->globals_size - addr))
PR_RunError (pr, "invalid memory access: %d (0 to %d-%d)", addr,
pr->globals_size, size);

View file

@ -103,13 +103,13 @@ GIB_Execute_Split_Var (cbuf_t * cbuf)
&GIB_DATA (cbuf)->globals,
str, &i, false)))
return;
if (end < 0)
if ((int) end < 0)
end += var->size;
else if (end > var->size)
end = var->size;
if (start < 0) {
if ((int) start < 0) {
start += var->size;
if (start < 0)
if ((int) start < 0)
start = 0;
} else if (start >= var->size || start >= end)
return;

View file

@ -1653,7 +1653,7 @@ static int
rua_init_runtime (progs_t *pr)
{
ddef_t *def;
int i;
unsigned i;
if (!pr->selector_hash)
pr->selector_hash = Hash_NewTable (1021, selector_get_key, 0, pr);

View file

@ -107,10 +107,10 @@ Hash_String (const char *str)
// dx_hack_hash
// shamelessly stolen from Daniel Phillips <phillips@innominate.de>
// from his post to lkml
unsigned long hash0 = 0x12a3fe2d, hash1 = 0x37abe8f9;
uint32_t hash0 = 0x12a3fe2d, hash1 = 0x37abe8f9;
while (*str) {
unsigned long hash = hash1 + (hash0 ^ ((unsigned char)*str++ * 71523));
if (hash < 0) hash -= 0x7fffffff;
uint32_t hash = hash1 + (hash0 ^ ((unsigned char)*str++ * 71523));
if (hash & 0x80000000) hash -= 0x7fffffff;
hash1 = hash0;
hash0 = hash;
}
@ -134,10 +134,10 @@ Hash_Buffer (const void *_buf, int len)
// dx_hack_hash
// shamelessly stolen from Daniel Phillips <phillips@innominate.de>
// from his post to lkml
unsigned long hash0 = 0x12a3fe2d, hash1 = 0x37abe8f9;
uint32_t hash0 = 0x12a3fe2d, hash1 = 0x37abe8f9;
while (len-- > 0) {
unsigned long hash = hash1 + (hash0 ^ ((unsigned char)*buf++ * 71523));
if (hash < 0) hash -= 0x7fffffff;
uint32_t hash = hash1 + (hash0 ^ ((unsigned char)*buf++ * 71523));
if (hash & 0x80000000) hash -= 0x7fffffff;
hash1 = hash0;
hash0 = hash;
}

View file

@ -68,7 +68,7 @@ noise_diamondsquare (unsigned char *noise, unsigned int size,
if (startgrid != (unsigned int) (1 << gridpower))
Sys_Error("fractalnoise: grid must be power of 2");
startgrid = bound(0, startgrid, size);
startgrid = min(startgrid, size);
amplitude = 0xFFFF; // this gets halved before use
noisebuf = calloc (size * size, sizeof (int));
memset(noisebuf, 0, size * size * sizeof(int));
@ -121,8 +121,8 @@ noise_diamondsquare (unsigned char *noise, unsigned int size,
void
noise_plasma (unsigned char *noise, int size)
{
unsigned int a, b, c, d, i;
int j, k;
unsigned int a, b, c, i;
int d, j, k;
if (128 >= size)
d = 64 / size;

View file

@ -305,7 +305,7 @@ static pt_phys_func part_phys[] = {
pt_phys_func
R_ParticlePhysics (ptype_t type)
{
if (type < pt_static || type > pt_flame)
if (type > pt_flame)
Sys_Error ("R_ParticlePhysics: invalid particle type");
return part_phys[type];
}

View file

@ -265,7 +265,7 @@ Draw_Character (int x, int y, unsigned int chr)
if (y > vid.conheight - 8 || x < 0 || x > vid.conwidth - 8)
return;
if (chr < 0 || chr > 255)
if (chr > 255)
return;
row = chr >> 4;

View file

@ -267,7 +267,7 @@ sw32_Draw_Character (int x, int y, unsigned int chr)
if (y > vid.conheight - 8 || x < 0 || x > vid.conwidth - 8)
return;
if (chr < 0 || chr > 255)
if (chr > 255)
return;
row = chr >> 4;

View file

@ -1319,8 +1319,8 @@ SV_StringToFilter (const char *address, ipfilter_t *f)
if (mask == -1) {
if (sv_filter_automask->int_val) {
mask = sizeof (b) * 8;
i = sizeof (b) - 1;
while (i >= 0 && !b[i]) {
i = sizeof (b);
while (i > 0 && !b[i - 1]) {
mask -= 8;
i--;
}

View file

@ -159,7 +159,7 @@ plotpoint (image_t *image, long xco, long yco, unsigned int color)
bigcol += color;
bigcol = bound (0, bigcol, 255);
bigcol = min (bigcol, 255);
image->image[yco * image->width + xco] = (eightbit) bigcol;

View file

@ -86,7 +86,7 @@ typedef struct qfo_space_s {
pr_int_t defs; ///< index of first def
pr_int_t num_defs; ///< zero for code or string spaces
pr_int_t data; ///< byte offset in qfo
pr_int_t data_size; ///< in elements. zero for entity spaces
pr_uint_t data_size; ///< in elements. zero for entity spaces
pr_int_t id;
pr_int_t reserved[2];
} qfo_space_t;
@ -240,7 +240,7 @@ typedef struct qfo_reloc_s {
pr_int_t space; ///< index of space holding data to be adjusted
pr_int_t offset; ///< offset of the relocation
pr_int_t type; ///< type of the relocation (::reloc_type)
pr_int_t target; ///< def/func/etc this relocation is for
pr_uint_t target; ///< def/func/etc this relocation is for
} qfo_reloc_t;
/** In-memory representation of a QFO space
@ -254,7 +254,7 @@ typedef struct qfo_mspace_s {
pr_type_t *data;
char *strings;
} d;
int data_size;
unsigned data_size;
int id;
} qfo_mspace_t;

View file

@ -1487,7 +1487,7 @@ fold_constants (expr_t *e)
if (op == 'A' || op == 'g' || op == 'r')
return e;
t1 = extract_type (e1);
if (t1 < 0 || t1 >= ev_type_count || !do_unary_op[t1]) {
if (t1 >= ev_type_count || !do_unary_op[t1]) {
print_expr (e);
internal_error (e, "invalid type: %d", t1);
}
@ -1519,7 +1519,7 @@ fold_constants (expr_t *e)
if (op == 's')
return e;
if (t1 < 0 || t1 >= ev_type_count || t2 < 0 || t2 >= ev_type_count
if (t1 >= ev_type_count || t2 >= ev_type_count
|| !do_op[t1] || !do_op[t1][t2])
internal_error (e, "invalid type");
return do_op[t1][t2] (op, e, e1, e2);

View file

@ -466,7 +466,7 @@ _print_expr (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
return;
e->printid = id;
if (e->type < 0 || e->type > ex_value) {
if ((int) e->type < 0 || e->type > ex_value) {
dasprintf (dstr, "%*se_%p [label=\"(bad expr type)\\n%d\"];\n",
indent, "", e, e->line);
return;

View file

@ -60,10 +60,9 @@ dump_lines (progs_t *pr)
if (!lineno->line) {
aux_func = 0;
func = 0;
if (lineno->fa.func >= 0
&& lineno->fa.func < pr->debug->num_auxfunctions)
if (lineno->fa.func < pr->debug->num_auxfunctions)
aux_func = pr->auxfunctions + lineno->fa.func;
if (aux_func && aux_func->function >= 0
if (aux_func
&& aux_func->function < (unsigned int) pr->progs->numfunctions)
func = pr->pr_functions + aux_func->function;
}

View file

@ -183,12 +183,12 @@ linker_type_mismatch (qfo_def_t *def, qfo_def_t *prev)
const char *def_encoding;
const char *prev_encoding;
if (def->type < 0)
def_encoding = QFO_GETSTR (work, -def->type);
if ((int) def->type < 0)
def_encoding = QFO_GETSTR (work, -(int) def->type);
else
def_encoding = QFO_TYPESTR (work, def->type);
if (prev->type < 0)
prev_encoding = QFO_GETSTR (work, -prev->type);
if ((int) prev->type < 0)
prev_encoding = QFO_GETSTR (work, -(int) prev->type);
else
prev_encoding = QFO_TYPESTR (work, prev->type);
def_error (def, "type mismatch for `%s' `%s'", WORKSTR (def->name),
@ -844,7 +844,7 @@ process_type_space (qfo_t *qfo, qfo_mspace_t *space, int pass)
if (!bi->defref)
continue;
def = REF (bi->defref);
if (def->type >= 0)
if ((int) def->type >= 0)
continue;
ref = Hash_Find (defined_type_defs, WORKSTR (-def->type));
if (!ref)
@ -926,8 +926,7 @@ process_loose_relocs (qfo_t *qfo)
if (reloc->type == rel_def_string) {
const char *str;
if (reloc->target < 0
|| reloc->target >= qfo->spaces[qfo_strings_space].data_size) {
if (reloc->target >= qfo->spaces[qfo_strings_space].data_size) {
linker_error ("bad string reloc at %d:%x", reloc->space,
reloc->offset);
reloc->target = 0;
@ -963,7 +962,7 @@ linker_add_qfo (qfo_t *qfo)
work_func_base = work->num_funcs;
for (pass = 0; pass < 2; pass++) {
for (i = 0, space = qfo->spaces; i < qfo->num_spaces; i++, space++) {
if (space->type < 0 || space->type > qfos_type) {
if ((int) space->type < 0 || space->type > qfos_type) {
linker_error ("bad space type");
return 1;
}

View file

@ -621,7 +621,7 @@ static etype_t
get_def_type (qfo_t *qfo, pointer_t type)
{
qfot_type_t *type_def;
if (type < 0 || type >= qfo->spaces[qfo_type_space].data_size)
if (type >= qfo->spaces[qfo_type_space].data_size)
return ev_void;
type_def = QFO_POINTER (qfo, qfo_type_space, qfot_type_t, type);
switch ((ty_meta_e)type_def->ty) {
@ -646,7 +646,7 @@ get_type_size (qfo_t *qfo, pointer_t type)
{
qfot_type_t *type_def;
int i, size;
if (type < 0 || type >= qfo->spaces[qfo_type_space].data_size)
if (type >= qfo->spaces[qfo_type_space].data_size)
return 1;
type_def = QFO_POINTER (qfo, qfo_type_space, qfot_type_t, type);
switch ((ty_meta_e)type_def->ty) {
@ -684,7 +684,7 @@ function_params (qfo_t *qfo, qfo_func_t *func, dfunction_t *df)
int num_params;
int i;
if (func->type < 0 || func->type >= qfo->spaces[qfo_type_space].data_size)
if (func->type >= qfo->spaces[qfo_type_space].data_size)
return;
type = QFO_POINTER (qfo, qfo_type_space, qfot_type_t, func->type);
if (type->ty != ty_none && type->t.type != ev_func)
@ -787,7 +787,7 @@ qfo_to_progs (qfo_t *qfo, int *size)
dprograms_t *progs;
qfo_def_t *types_def = 0;
int i, j;
int locals_size = 0;
unsigned locals_size = 0;
int locals_start;
int big_locals = 0;
int big_func = 0;

View file

@ -273,7 +273,7 @@ qfo_encode_type (type_t *type)
}
if (type->type_def)
return type->type_def;
if (type->meta < 0 || type->meta > ty_class)
if (type->meta > ty_class)
internal_error (0, "bad type meta type");
if (!type->encoding)
type->encoding = type_get_encoding (type);

View file

@ -67,7 +67,7 @@ static const char *op_type_names[] = {
const char *
optype_str (op_type_e type)
{
if (type < 0 || type > op_temp)
if (type > op_temp)
return "<invalid op_type>";
return op_type_names[type];
}
@ -1011,7 +1011,7 @@ statement_subexpr (sblock_t *sblock, expr_t *e, operand_t **op)
return sblock;
}
if (e->type < 0 || e->type > ex_value)
if (e->type > ex_value)
internal_error (e, "bad expression type");
if (!sfuncs[e->type])
internal_error (e, "unexpected expression type");
@ -1287,7 +1287,7 @@ statement_slist (sblock_t *sblock, expr_t *e)
};
for (/**/; e; e = e->next) {
if (e->type < 0 || e->type > ex_value)
if (e->type > ex_value)
internal_error (e, "bad expression type");
sblock = sfuncs[e->type] (sblock, e);
}

View file

@ -63,7 +63,7 @@ static const char *sy_type_names[] = {
const char *
symtype_str (sy_type_e type)
{
if (type < 0 || type > sy_class)
if (type > sy_class)
return "<invalid sy_type>";
return sy_type_names[type];
}

View file

@ -93,7 +93,7 @@ static type_t *free_types;
etype_t
low_level_type (type_t *type)
{
if (type->type < 0 || type->type >= ev_type_count)
if (type->type >= ev_type_count)
internal_error (0, "invalid type");
if (type->type == ev_type_count)
internal_error (0, "found 'type count' type");