diff --git a/src/core/ldebug.cpp b/src/core/ldebug.cpp index 5eb4e364..51bd8c9f 100644 --- a/src/core/ldebug.cpp +++ b/src/core/ldebug.cpp @@ -96,9 +96,10 @@ int luaG_getfuncline (const Proto *f, int pc) { else { int basepc; int baseline = getbaseline(f, pc, &basepc); - while (basepc++ < pc) { /* walk until given instruction */ - lua_assert(lineInfoSpan[basepc] != ABSLINEINFO); - baseline += lineInfoSpan[basepc]; /* correct line */ + /* Walk from basepc+1 to pc (inclusive), accumulating line deltas */ + for (size_t i = static_cast(basepc + 1); i <= static_cast(pc); i++) { + lua_assert(lineInfoSpan[i] != ABSLINEINFO); + baseline += lineInfoSpan[i]; /* correct line */ } return baseline; } @@ -295,12 +296,12 @@ static void funcinfo (lua_Debug *ar, Closure *cl) { // Phase 115.2: Use span accessors -static int nextline (const Proto *p, int currentline, int pc) { +static int nextline (const Proto *p, int currentline, size_t pc) { auto lineInfoSpan = p->getDebugInfo().getLineInfoSpan(); if (lineInfoSpan[pc] != ABSLINEINFO) return currentline + lineInfoSpan[pc]; else - return luaG_getfuncline(p, pc); + return luaG_getfuncline(p, static_cast(pc)); } @@ -317,7 +318,7 @@ static void collectvalidlines (lua_State *L, Closure *f) { api_incr_top(L); auto lineInfoSpan = p->getDebugInfo().getLineInfoSpan(); if (!lineInfoSpan.empty()) { /* proto with debug information? */ - int i; + size_t i; TValue v; setbtvalue(&v); /* boolean 'true' to be the value of all indices */ if (!(p->getFlag() & PF_ISVARARG)) /* regular function? */ @@ -328,7 +329,7 @@ static void collectvalidlines (lua_State *L, Closure *f) { currentline = nextline(p, currentline, 0); i = 1; /* skip first instruction (OP_VARARGPREP) */ } - for (; i < static_cast(lineInfoSpan.size()); i++) { /* for each instruction */ + for (; i < lineInfoSpan.size(); i++) { /* for each instruction */ currentline = nextline(p, currentline, i); /* get its line */ luaH_setint(L, t, currentline, &v); /* table[line] = true */ } @@ -953,13 +954,14 @@ static int changedline (const Proto *p, int oldpc, int newpc) { return 0; if (newpc - oldpc < MAXIWTHABS / 2) { /* not too far apart? */ int delta = 0; /* line difference */ - int pc = oldpc; + size_t pc = static_cast(oldpc); for (;;) { - int lineinfo = lineInfoSpan[++pc]; + ++pc; + int lineinfo = lineInfoSpan[pc]; if (lineinfo == ABSLINEINFO) break; /* cannot compute delta; fall through */ delta += lineinfo; - if (pc == newpc) + if (static_cast(pc) == newpc) return (delta != 0); /* delta computed successfully */ } } diff --git a/src/objects/ltable.cpp b/src/objects/ltable.cpp index 05b25c13..625c5325 100644 --- a/src/objects/ltable.cpp +++ b/src/objects/ltable.cpp @@ -111,7 +111,7 @@ class NodeArray { // Large table: allocate Limbox + Node[] // LAYOUT: [Limbox header][Node array of size n] // Verify no overflow in size calculation - if (n > (MAX_SIZET - sizeof(Limbox)) / sizeof(Node)) { + if (static_cast(n) > (MAX_SIZET - sizeof(Limbox)) / sizeof(Node)) { luaG_runerror(L, "table size overflow"); } size_t total = sizeof(Limbox) + n * sizeof(Node); diff --git a/src/serialization/lundump.cpp b/src/serialization/lundump.cpp index 78bc6150..484f29f4 100644 --- a/src/serialization/lundump.cpp +++ b/src/serialization/lundump.cpp @@ -213,7 +213,6 @@ static void loadFunction(LoadState *S, Proto *f); // Phase 115.2: Use span accessors static void loadConstants (LoadState *S, Proto *f) { - int i; int n = loadInt(S); f->setConstants(luaM_newvectorchecked(S->L, n, TValue)); f->setConstantsSize(n); @@ -221,7 +220,7 @@ static void loadConstants (LoadState *S, Proto *f) { for (TValue& v : constantsSpan) { setnilvalue(&v); } - for (i = 0; i < n; i++) { + for (size_t i = 0; i < static_cast(n); i++) { TValue *o = &constantsSpan[i]; int t = loadByte(S); switch (t) { @@ -278,7 +277,6 @@ static void loadProtos (LoadState *S, Proto *f) { */ // Phase 115.2: Use span accessors static void loadUpvalues (LoadState *S, Proto *f) { - int i; int n = loadInt(S); f->setUpvalues(luaM_newvectorchecked(S->L, n, Upvaldesc)); f->setUpvaluesSize(n); @@ -287,7 +285,7 @@ static void loadUpvalues (LoadState *S, Proto *f) { for (Upvaldesc& uv : upvaluesSpan) { uv.setName(nullptr); } - for (i = 0; i < n; i++) { /* following calls can raise errors */ + for (size_t i = 0; i < static_cast(n); i++) { /* following calls can raise errors */ upvaluesSpan[i].setInStack(loadByte(S)); upvaluesSpan[i].setIndex(loadByte(S)); upvaluesSpan[i].setKind(loadByte(S)); @@ -297,7 +295,6 @@ static void loadUpvalues (LoadState *S, Proto *f) { // Phase 115.2: Use span accessors static void loadDebug (LoadState *S, Proto *f) { - int i; int n = loadInt(S); if (S->fixed) { f->setLineInfo(getaddr(S, n, ls_byte)); @@ -330,7 +327,7 @@ static void loadDebug (LoadState *S, Proto *f) { for (LocVar& lv : locVarsSpan) { lv.setVarName(nullptr); } - for (i = 0; i < n; i++) { + for (size_t i = 0; i < static_cast(n); i++) { loadString(S, f, locVarsSpan[i].getVarNamePtr()); locVarsSpan[i].setStartPC(loadInt(S)); locVarsSpan[i].setEndPC(loadInt(S)); @@ -339,7 +336,7 @@ static void loadDebug (LoadState *S, Proto *f) { if (n != 0) /* does it have debug information? */ n = f->getUpvaluesSize(); /* must be this many */ auto upvaluesSpan = f->getUpvaluesSpan(); - for (i = 0; i < n; i++) + for (size_t i = 0; i < static_cast(n); i++) loadString(S, f, upvaluesSpan[i].getNamePtr()); }