1
0
mirror of https://github.com/lua/lua.git synced 2025-01-28 06:03:00 +08:00

Fixed conversion warnings from clang

Plus some other details. (Option '-Wuninitialized' was removed from
the makefile because it is already enabled by -Wall.)
This commit is contained in:
Roberto Ierusalimschy 2025-01-14 16:24:46 -03:00
parent 10e931da82
commit 3cdd49c94a
9 changed files with 17 additions and 13 deletions

View File

@ -1439,7 +1439,7 @@ static void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2,
e1->u.info = pc; e1->u.info = pc;
e1->k = VRELOC; /* all those operations are relocatable */ e1->k = VRELOC; /* all those operations are relocatable */
luaK_fixline(fs, line); luaK_fixline(fs, line);
luaK_codeABCk(fs, mmop, v1, v2, event, flip); /* to call metamethod */ luaK_codeABCk(fs, mmop, v1, v2, cast_int(event), flip); /* metamethod */
luaK_fixline(fs, line); luaK_fixline(fs, line);
} }

7
llex.c
View File

@ -349,9 +349,14 @@ static int readhexaesc (LexState *ls) {
} }
/*
** When reading a UTF-8 escape sequence, save everything to the buffer
** for error reporting in case of errors; 'i' counts the number of
** saved characters, so that they can be removed if case of success.
*/
static unsigned long readutf8esc (LexState *ls) { static unsigned long readutf8esc (LexState *ls) {
unsigned long r; unsigned long r;
int i = 4; /* chars to be removed: '\', 'u', '{', and first digit */ int i = 4; /* number of chars to be removed: start with #"\u{X" */
save_and_next(ls); /* skip 'u' */ save_and_next(ls); /* skip 'u' */
esccheck(ls, ls->current == '{', "missing '{'"); esccheck(ls, ls->current == '{', "missing '{'");
r = cast_ulong(gethexa(ls)); /* must have at least one digit */ r = cast_ulong(gethexa(ls)); /* must have at least one digit */

4
lmem.h
View File

@ -39,11 +39,11 @@
** Computes the minimum between 'n' and 'MAX_SIZET/sizeof(t)', so that ** Computes the minimum between 'n' and 'MAX_SIZET/sizeof(t)', so that
** the result is not larger than 'n' and cannot overflow a 'size_t' ** the result is not larger than 'n' and cannot overflow a 'size_t'
** when multiplied by the size of type 't'. (Assumes that 'n' is an ** when multiplied by the size of type 't'. (Assumes that 'n' is an
** 'int' or 'unsigned int' and that 'int' is not larger than 'size_t'.) ** 'int' and that 'int' is not larger than 'size_t'.)
*/ */
#define luaM_limitN(n,t) \ #define luaM_limitN(n,t) \
((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) : \ ((cast_sizet(n) <= MAX_SIZET/sizeof(t)) ? (n) : \
cast_uint((MAX_SIZET/sizeof(t)))) cast_int((MAX_SIZET/sizeof(t))))
/* /*

View File

@ -194,6 +194,7 @@ void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,
lu_byte luaO_hexavalue (int c) { lu_byte luaO_hexavalue (int c) {
lua_assert(lisxdigit(c));
if (lisdigit(c)) return cast_byte(c - '0'); if (lisdigit(c)) return cast_byte(c - '0');
else return cast_byte((ltolower(c) - 'a') + 10); else return cast_byte((ltolower(c) - 'a') + 10);
} }

View File

@ -405,7 +405,7 @@ static int searchvar (FuncState *fs, TString *n, expdesc *var) {
init_exp(var, VCONST, fs->firstlocal + i); init_exp(var, VCONST, fs->firstlocal + i);
else /* real variable */ else /* real variable */
init_var(fs, var, i); init_var(fs, var, i);
return var->k; return cast_int(var->k);
} }
} }
return -1; /* not found */ return -1; /* not found */

View File

@ -96,7 +96,7 @@ typedef union {
** between 2^MAXHBITS and the maximum size such that, measured in bytes, ** between 2^MAXHBITS and the maximum size such that, measured in bytes,
** it fits in a 'size_t'. ** it fits in a 'size_t'.
*/ */
#define MAXHSIZE luaM_limitN(1u << MAXHBITS, Node) #define MAXHSIZE luaM_limitN(1 << MAXHBITS, Node)
/* /*
@ -598,7 +598,7 @@ static void setnodevector (lua_State *L, Table *t, unsigned size) {
else { else {
int i; int i;
int lsize = luaO_ceillog2(size); int lsize = luaO_ceillog2(size);
if (lsize > MAXHBITS || (1u << lsize) > MAXHSIZE) if (lsize > MAXHBITS || (1 << lsize) > MAXHSIZE)
luaG_runerror(L, "table overflow"); luaG_runerror(L, "table overflow");
size = twoto(lsize); size = twoto(lsize);
if (lsize < LIMFORLAST) /* no 'lastfree' field? */ if (lsize < LIMFORLAST) /* no 'lastfree' field? */

View File

@ -15,7 +15,6 @@ CWARNSCPP= \
-Wdouble-promotion \ -Wdouble-promotion \
-Wmissing-declarations \ -Wmissing-declarations \
-Wconversion \ -Wconversion \
-Wuninitialized \
-Wstrict-overflow=2 \ -Wstrict-overflow=2 \
# the next warnings might be useful sometimes, # the next warnings might be useful sometimes,
# but usually they generate too much noise # but usually they generate too much noise

View File

@ -3848,7 +3848,6 @@ or zero if the value at @id{idx} is not a number.
Calls a function (or a callable object) in protected mode. Calls a function (or a callable object) in protected mode.
Both @id{nargs} and @id{nresults} have the same meaning as Both @id{nargs} and @id{nresults} have the same meaning as
in @Lid{lua_call}. in @Lid{lua_call}.
If there are no errors during the call, If there are no errors during the call,
@ -3998,9 +3997,9 @@ Lua will call @id{falloc} before raising the error.
Pushes onto the stack a formatted string Pushes onto the stack a formatted string
and returns a pointer to this string @see{constchar}. and returns a pointer to this string @see{constchar}.
The result is a copy of @id{fmt} with The result is a copy of @id{fmt} with
each @emph{conversion specifier} replaced by its respective each @emph{conversion specifier} replaced by a string representation
extra argument. of its respective extra argument.
A conversion specifier can be A conversion specifier (and its corresponding extra argument) can be
@Char{%%} (inserts the character @Char{%}), @Char{%%} (inserts the character @Char{%}),
@Char{%s} (inserts a zero-terminated string, with no size restrictions), @Char{%s} (inserts a zero-terminated string, with no size restrictions),
@Char{%f} (inserts a @Lid{lua_Number}), @Char{%f} (inserts a @Lid{lua_Number}),

View File

@ -5,7 +5,7 @@ LUA_DIR = ../../
CC = gcc CC = gcc
# compilation should generate Dynamic-Link Libraries # compilation should generate Dynamic-Link Libraries
CFLAGS = -Wall -std=gnu99 -O2 -I$(LUA_DIR) -fPIC -shared CFLAGS = -Wall -std=c99 -O2 -I$(LUA_DIR) -fPIC -shared
# libraries used by the tests # libraries used by the tests
all: lib1.so lib11.so lib2.so lib21.so lib2-v2.so all: lib1.so lib11.so lib2.so lib21.so lib2-v2.so