Skip to content

Commit 0acd558

Browse files
committed
Added gcc option '-Wconversion'
No warnings for standard numerical types. Still pending alternative numerical types.
1 parent 15231d4 commit 0acd558

44 files changed

Lines changed: 398 additions & 359 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

lapi.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static void advancegc (lua_State *L, size_t delta) {
5858
delta >>= 5; /* one object for each 32 bytes (empirical) */
5959
if (delta > 0) {
6060
global_State *g = G(L);
61-
luaE_setdebt(g, g->GCdebt - delta);
61+
luaE_setdebt(g, g->GCdebt - cast(l_obj, delta));
6262
}
6363
}
6464

@@ -437,9 +437,9 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
437437
LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) {
438438
const TValue *o = index2value(L, idx);
439439
switch (ttypetag(o)) {
440-
case LUA_VSHRSTR: return tsvalue(o)->shrlen;
441-
case LUA_VLNGSTR: return tsvalue(o)->u.lnglen;
442-
case LUA_VUSERDATA: return uvalue(o)->len;
440+
case LUA_VSHRSTR: return cast(lua_Unsigned, tsvalue(o)->shrlen);
441+
case LUA_VLNGSTR: return cast(lua_Unsigned, tsvalue(o)->u.lnglen);
442+
case LUA_VUSERDATA: return cast(lua_Unsigned, uvalue(o)->len);
443443
case LUA_VTABLE: return luaH_getn(hvalue(o));
444444
default: return 0;
445445
}
@@ -667,7 +667,7 @@ LUA_API int lua_pushthread (lua_State *L) {
667667

668668

669669
static int auxgetstr (lua_State *L, const TValue *t, const char *k) {
670-
int tag;
670+
lu_byte tag;
671671
TString *str = luaS_new(L, k);
672672
luaV_fastget(t, str, s2v(L->top.p), luaH_getstr, tag);
673673
if (!tagisempty(tag)) {
@@ -685,7 +685,7 @@ static int auxgetstr (lua_State *L, const TValue *t, const char *k) {
685685

686686
static void getGlobalTable (lua_State *L, TValue *gt) {
687687
Table *registry = hvalue(&G(L)->l_registry);
688-
int tag = luaH_getint(registry, LUA_RIDX_GLOBALS, gt);
688+
lu_byte tag = luaH_getint(registry, LUA_RIDX_GLOBALS, gt);
689689
(void)tag; /* avoid not-used warnings when checks are off */
690690
api_check(L, novariant(tag) == LUA_TTABLE, "global table must exist");
691691
}
@@ -700,7 +700,7 @@ LUA_API int lua_getglobal (lua_State *L, const char *name) {
700700

701701

702702
LUA_API int lua_gettable (lua_State *L, int idx) {
703-
int tag;
703+
lu_byte tag;
704704
TValue *t;
705705
lua_lock(L);
706706
api_checkpop(L, 1);
@@ -721,7 +721,7 @@ LUA_API int lua_getfield (lua_State *L, int idx, const char *k) {
721721

722722
LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
723723
TValue *t;
724-
int tag;
724+
lu_byte tag;
725725
lua_lock(L);
726726
t = index2value(L, idx);
727727
luaV_fastgeti(t, n, s2v(L->top.p), tag);
@@ -736,7 +736,7 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
736736
}
737737

738738

739-
static int finishrawget (lua_State *L, int tag) {
739+
static int finishrawget (lua_State *L, lu_byte tag) {
740740
if (tagisempty(tag)) /* avoid copying empty items to the stack */
741741
setnilvalue(s2v(L->top.p));
742742
api_incr_top(L);
@@ -754,7 +754,7 @@ l_sinline Table *gettable (lua_State *L, int idx) {
754754

755755
LUA_API int lua_rawget (lua_State *L, int idx) {
756756
Table *t;
757-
int tag;
757+
lu_byte tag;
758758
lua_lock(L);
759759
api_checkpop(L, 1);
760760
t = gettable(L, idx);
@@ -766,7 +766,7 @@ LUA_API int lua_rawget (lua_State *L, int idx) {
766766

767767
LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) {
768768
Table *t;
769-
int tag;
769+
lu_byte tag;
770770
lua_lock(L);
771771
t = gettable(L, idx);
772772
luaH_fastgeti(t, n, s2v(L->top.p), tag);
@@ -1231,7 +1231,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
12311231
api_check(L, 0 <= param && param < LUA_GCPN, "invalid parameter");
12321232
res = cast_int(luaO_applyparam(g->gcparams[param], 100));
12331233
if (value >= 0)
1234-
g->gcparams[param] = luaO_codeparam(value);
1234+
g->gcparams[param] = luaO_codeparam(cast_uint(value));
12351235
break;
12361236
}
12371237
default: res = -1; /* invalid option */
@@ -1353,7 +1353,7 @@ LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) {
13531353
Udata *u;
13541354
lua_lock(L);
13551355
api_check(L, 0 <= nuvalue && nuvalue < USHRT_MAX, "invalid value");
1356-
u = luaS_newudata(L, size, nuvalue);
1356+
u = luaS_newudata(L, size, cast(unsigned short, nuvalue));
13571357
setuvalue(L, s2v(L->top.p), u);
13581358
api_incr_top(L);
13591359
advancegc(L, size);

lauxlib.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ static void newbox (lua_State *L) {
539539
static size_t newbuffsize (luaL_Buffer *B, size_t sz) {
540540
size_t newsize = (B->size / 2) * 3; /* buffer size * 1.5 */
541541
if (l_unlikely(sz > MAX_SIZE - B->n - 1))
542-
return luaL_error(B->L, "resulting string too large");
542+
return cast_sizet(luaL_error(B->L, "resulting string too large"));
543543
if (newsize < B->n + sz + 1 || newsize > MAX_SIZE) {
544544
/* newsize was not big enough or too big */
545545
newsize = B->n + sz + 1;
@@ -725,7 +725,7 @@ LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
725725
*/
726726

727727
typedef struct LoadF {
728-
int n; /* number of pre-read characters */
728+
unsigned n; /* number of pre-read characters */
729729
FILE *f; /* file being read */
730730
char buff[BUFSIZ]; /* area for reading file */
731731
} LoadF;
@@ -825,7 +825,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
825825
}
826826
}
827827
if (c != EOF)
828-
lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
828+
lf.buff[lf.n++] = cast_char(c); /* 'c' is the first character */
829829
status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);
830830
readstatus = ferror(lf.f);
831831
errno = 0; /* no useful error number until here */
@@ -1020,7 +1020,7 @@ LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,
10201020
const char *wild;
10211021
size_t l = strlen(p);
10221022
while ((wild = strstr(s, p)) != NULL) {
1023-
luaL_addlstring(b, s, wild - s); /* push prefix */
1023+
luaL_addlstring(b, s, ct_diff2sz(wild - s)); /* push prefix */
10241024
luaL_addstring(b, r); /* push replacement in place of pattern */
10251025
s = wild + l; /* continue after 'p' */
10261026
}

lbaselib.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,22 @@ static int luaB_warn (lua_State *L) {
5858

5959
#define SPACECHARS " \f\n\r\t\v"
6060

61-
static const char *b_str2int (const char *s, int base, lua_Integer *pn) {
61+
static const char *b_str2int (const char *s, unsigned base, lua_Integer *pn) {
6262
lua_Unsigned n = 0;
6363
int neg = 0;
6464
s += strspn(s, SPACECHARS); /* skip initial spaces */
6565
if (*s == '-') { s++; neg = 1; } /* handle sign */
6666
else if (*s == '+') s++;
67-
if (!isalnum((unsigned char)*s)) /* no digit? */
67+
if (!isalnum(cast_uchar(*s))) /* no digit? */
6868
return NULL;
6969
do {
70-
int digit = (isdigit((unsigned char)*s)) ? *s - '0'
71-
: (toupper((unsigned char)*s) - 'A') + 10;
70+
unsigned digit = cast_uint(isdigit(cast_uchar(*s))
71+
? *s - '0'
72+
: (toupper(cast_uchar(*s)) - 'A') + 10);
7273
if (digit >= base) return NULL; /* invalid numeral */
7374
n = n * base + digit;
7475
s++;
75-
} while (isalnum((unsigned char)*s));
76+
} while (isalnum(cast_uchar(*s)));
7677
s += strspn(s, SPACECHARS); /* skip trailing spaces */
7778
*pn = (lua_Integer)((neg) ? (0u - n) : n);
7879
return s;
@@ -102,7 +103,7 @@ static int luaB_tonumber (lua_State *L) {
102103
luaL_checktype(L, 1, LUA_TSTRING); /* no numbers as strings */
103104
s = lua_tolstring(L, 1, &l);
104105
luaL_argcheck(L, 2 <= base && base <= 36, 2, "base out of range");
105-
if (b_str2int(s, (int)base, &n) == s + l) {
106+
if (b_str2int(s, cast_uint(base), &n) == s + l) {
106107
lua_pushinteger(L, n);
107108
return 1;
108109
} /* else not a number */
@@ -159,7 +160,7 @@ static int luaB_rawlen (lua_State *L) {
159160
int t = lua_type(L, 1);
160161
luaL_argexpected(L, t == LUA_TTABLE || t == LUA_TSTRING, 1,
161162
"table or string");
162-
lua_pushinteger(L, lua_rawlen(L, 1));
163+
lua_pushinteger(L, l_castU2S(lua_rawlen(L, 1)));
163164
return 1;
164165
}
165166

lcode.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static void savelineinfo (FuncState *fs, Proto *f, int line) {
335335
}
336336
luaM_growvector(fs->ls->L, f->lineinfo, pc, f->sizelineinfo, ls_byte,
337337
INT_MAX, "opcodes");
338-
f->lineinfo[pc] = linedif;
338+
f->lineinfo[pc] = cast(ls_byte, linedif);
339339
fs->previousline = line; /* last line saved */
340340
}
341341

@@ -409,7 +409,7 @@ int luaK_codevABCk (FuncState *fs, OpCode o, int A, int B, int C, int k) {
409409
/*
410410
** Format and emit an 'iABx' instruction.
411411
*/
412-
int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bc) {
412+
int luaK_codeABx (FuncState *fs, OpCode o, int A, int Bc) {
413413
lua_assert(getOpMode(o) == iABx);
414414
lua_assert(A <= MAXARG_A && Bc <= MAXARG_Bx);
415415
return luaK_code(fs, CREATE_ABx(o, A, Bc));
@@ -420,7 +420,7 @@ int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bc) {
420420
** Format and emit an 'iAsBx' instruction.
421421
*/
422422
static int codeAsBx (FuncState *fs, OpCode o, int A, int Bc) {
423-
unsigned int b = cast_uint(Bc) + OFFSET_sBx;
423+
int b = Bc + OFFSET_sBx;
424424
lua_assert(getOpMode(o) == iAsBx);
425425
lua_assert(A <= MAXARG_A && b <= MAXARG_Bx);
426426
return luaK_code(fs, CREATE_ABx(o, A, b));
@@ -431,7 +431,7 @@ static int codeAsBx (FuncState *fs, OpCode o, int A, int Bc) {
431431
** Format and emit an 'isJ' instruction.
432432
*/
433433
static int codesJ (FuncState *fs, OpCode o, int sj, int k) {
434-
unsigned int j = cast_uint(sj) + OFFSET_sJ;
434+
int j = sj + OFFSET_sJ;
435435
lua_assert(getOpMode(o) == isJ);
436436
lua_assert(j <= MAXARG_sJ && (k & ~1) == 0);
437437
return luaK_code(fs, CREATE_sJ(o, j, k));
@@ -483,7 +483,7 @@ void luaK_checkstack (FuncState *fs, int n) {
483483
*/
484484
void luaK_reserveregs (FuncState *fs, int n) {
485485
luaK_checkstack(fs, n);
486-
fs->freereg += n;
486+
fs->freereg = cast_byte(fs->freereg + n);
487487
}
488488

489489

@@ -1290,25 +1290,25 @@ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
12901290
if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non 'Kstr'? */
12911291
luaK_exp2anyreg(fs, t); /* put it in a register */
12921292
if (t->k == VUPVAL) {
1293-
int temp = t->u.info; /* upvalue index */
1293+
lu_byte temp = cast_byte(t->u.info); /* upvalue index */
12941294
lua_assert(isKstr(fs, k));
12951295
t->u.ind.t = temp; /* (can't do a direct assignment; values overlap) */
1296-
t->u.ind.idx = k->u.info; /* literal short string */
1296+
t->u.ind.idx = cast(short, k->u.info); /* literal short string */
12971297
t->k = VINDEXUP;
12981298
}
12991299
else {
13001300
/* register index of the table */
1301-
t->u.ind.t = (t->k == VLOCAL) ? t->u.var.ridx: t->u.info;
1301+
t->u.ind.t = cast_byte((t->k == VLOCAL) ? t->u.var.ridx: t->u.info);
13021302
if (isKstr(fs, k)) {
1303-
t->u.ind.idx = k->u.info; /* literal short string */
1303+
t->u.ind.idx = cast(short, k->u.info); /* literal short string */
13041304
t->k = VINDEXSTR;
13051305
}
1306-
else if (isCint(k)) {
1307-
t->u.ind.idx = cast_int(k->u.ival); /* int. constant in proper range */
1306+
else if (isCint(k)) { /* int. constant in proper range? */
1307+
t->u.ind.idx = cast(short, k->u.ival);
13081308
t->k = VINDEXI;
13091309
}
13101310
else {
1311-
t->u.ind.idx = luaK_exp2anyreg(fs, k); /* register */
1311+
t->u.ind.idx = cast(short, luaK_exp2anyreg(fs, k)); /* register */
13121312
t->k = VINDEXED;
13131313
}
13141314
}
@@ -1623,7 +1623,7 @@ void luaK_prefix (FuncState *fs, UnOpr opr, expdesc *e, int line) {
16231623
luaK_dischargevars(fs, e);
16241624
switch (opr) {
16251625
case OPR_MINUS: case OPR_BNOT: /* use 'ef' as fake 2nd operand */
1626-
if (constfolding(fs, opr + LUA_OPUNM, e, &ef))
1626+
if (constfolding(fs, cast_int(opr + LUA_OPUNM), e, &ef))
16271627
break;
16281628
/* else */ /* FALLTHROUGH */
16291629
case OPR_LEN:
@@ -1711,7 +1711,7 @@ static void codeconcat (FuncState *fs, expdesc *e1, expdesc *e2, int line) {
17111711
void luaK_posfix (FuncState *fs, BinOpr opr,
17121712
expdesc *e1, expdesc *e2, int line) {
17131713
luaK_dischargevars(fs, e2);
1714-
if (foldbinop(opr) && constfolding(fs, opr + LUA_OPADD, e1, e2))
1714+
if (foldbinop(opr) && constfolding(fs, cast_int(opr + LUA_OPADD), e1, e2))
17151715
return; /* done by folding */
17161716
switch (opr) {
17171717
case OPR_AND: {
@@ -1797,11 +1797,11 @@ void luaK_fixline (FuncState *fs, int line) {
17971797

17981798
void luaK_settablesize (FuncState *fs, int pc, int ra, int asize, int hsize) {
17991799
Instruction *inst = &fs->f->code[pc];
1800-
int rb = (hsize != 0) ? luaO_ceillog2(hsize) + 1 : 0; /* hash size */
18011800
int extra = asize / (MAXARG_vC + 1); /* higher bits of array size */
18021801
int rc = asize % (MAXARG_vC + 1); /* lower bits of array size */
18031802
int k = (extra > 0); /* true iff needs extra argument */
1804-
*inst = CREATE_vABCk(OP_NEWTABLE, ra, rb, rc, k);
1803+
hsize = (hsize != 0) ? luaO_ceillog2(cast_uint(hsize)) + 1 : 0;
1804+
*inst = CREATE_vABCk(OP_NEWTABLE, ra, hsize, rc, k);
18051805
*(inst + 1) = CREATE_Ax(OP_EXTRAARG, extra);
18061806
}
18071807

@@ -1825,7 +1825,7 @@ void luaK_setlist (FuncState *fs, int base, int nelems, int tostore) {
18251825
luaK_codevABCk(fs, OP_SETLIST, base, tostore, nelems, 1);
18261826
codeextraarg(fs, extra);
18271827
}
1828-
fs->freereg = base + 1; /* free registers with list values */
1828+
fs->freereg = cast_byte(base + 1); /* free registers with list values */
18291829
}
18301830

18311831

lcode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef enum UnOpr { OPR_MINUS, OPR_BNOT, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
6060
#define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t)
6161

6262
LUAI_FUNC int luaK_code (FuncState *fs, Instruction i);
63-
LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned Bx);
63+
LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, int Bx);
6464
LUAI_FUNC int luaK_codeABCk (FuncState *fs, OpCode o, int A, int B, int C,
6565
int k);
6666
LUAI_FUNC int luaK_codevABCk (FuncState *fs, OpCode o, int A, int B, int C,

ldebug.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static int getbaseline (const Proto *f, int pc, int *basepc) {
6363
return f->linedefined;
6464
}
6565
else {
66-
int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */
66+
int i = pc / MAXIWTHABS - 1; /* get an estimate */
6767
/* estimate must be a lower bound of the correct base */
6868
lua_assert(i < 0 ||
6969
(i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc));
@@ -921,7 +921,7 @@ int luaG_tracecall (lua_State *L) {
921921
*/
922922
int luaG_traceexec (lua_State *L, const Instruction *pc) {
923923
CallInfo *ci = L->ci;
924-
lu_byte mask = L->hookmask;
924+
lu_byte mask = cast_byte(L->hookmask);
925925
const Proto *p = ci_func(ci)->p;
926926
int counthook;
927927
if (!(mask & (LUA_MASKLINE | LUA_MASKCOUNT))) { /* no hooks? */

ldo.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ int luaD_reallocstack (lua_State *L, int newsize, int raiseerror) {
241241
int oldsize = stacksize(L);
242242
int i;
243243
StkId newstack;
244-
int oldgcstop = G(L)->gcstopem;
244+
lu_byte oldgcstop = G(L)->gcstopem;
245245
lua_assert(newsize <= MAXSTACK || newsize == ERRORSTACKSIZE);
246246
relstack(L); /* change pointers to offsets */
247247
G(L)->gcstopem = 1; /* stop emergency collection */
@@ -357,7 +357,7 @@ void luaD_hook (lua_State *L, int event, int line,
357357
int ftransfer, int ntransfer) {
358358
lua_Hook hook = L->hook;
359359
if (hook && L->allowhook) { /* make sure there is a hook */
360-
int mask = CIST_HOOKED;
360+
unsigned mask = CIST_HOOKED;
361361
CallInfo *ci = L->ci;
362362
ptrdiff_t top = savestack(L, L->top.p); /* preserve original 'top' */
363363
ptrdiff_t ci_top = savestack(L, ci->top.p); /* idem for 'ci->top' */
@@ -1058,9 +1058,9 @@ int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
10581058
luaZ_initbuffer(L, &p.buff);
10591059
status = luaD_pcall(L, f_parser, &p, savestack(L, L->top.p), L->errfunc);
10601060
luaZ_freebuffer(L, &p.buff);
1061-
luaM_freearray(L, p.dyd.actvar.arr, p.dyd.actvar.size);
1062-
luaM_freearray(L, p.dyd.gt.arr, p.dyd.gt.size);
1063-
luaM_freearray(L, p.dyd.label.arr, p.dyd.label.size);
1061+
luaM_freearray(L, p.dyd.actvar.arr, cast_sizet(p.dyd.actvar.size));
1062+
luaM_freearray(L, p.dyd.gt.arr, cast_sizet(p.dyd.gt.size));
1063+
luaM_freearray(L, p.dyd.label.arr, cast_sizet(p.dyd.label.size));
10641064
decnny(L);
10651065
return status;
10661066
}

0 commit comments

Comments
 (0)