lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


The previous attempt to use this tool (www.gimpel.com) was done by David Manura
(see http://lua-users.org/lists/lua-l/2011-09/msg00805.html)

This kind of tool
(http://en.wikipedia.org/wiki/Static_program_analysis) allows to
enforce coding standards
(especially with a permissive language like C), to improve readability
of code, and sometime to find a bug.

You could find in attachment, some patches which fix very minor
problems (not bug).

My configuration file is available on
https://raw.githubusercontent.com/fperrad/misc/master/vm-script/lua/lua.lnt
This configuration catches all messages produced by lint.
On demand, I could send the messages produced for any kind of warnings.

François
ldo.c: Warning 438: Last value assigned to variable not used

--- Module:   src/ldo.c (C)
                               _
  return (wanted - LUA_MULTRET);  /* 0 iff wanted == LUA_MULTRET */
src/ldo.c  403  Warning 438: Last value assigned to variable 'ci' (defined at line 385) not used [MISRA 2012 Rule 2.2, required]

diff --git a/src/ldo.c b/src/ldo.c
index 6159e51..5c9c7f5 100644
--- a/src/ldo.c
+++ b/src/ldo.c
@@ -393,7 +393,7 @@
   }
   res = ci->func;  /* res == final position of 1st result */
   wanted = ci->nresults;
-  L->ci = ci = ci->previous;  /* back to caller */
+  L->ci = ci->previous;  /* back to caller */
   /* move results to correct place */
   for (i = wanted; i != 0 && firstResult < L->top; i--)
     setobjs2s(L, res++, firstResult++);
-- 

Warning 546: Suspicious use of &

remove useless &

diff --git a/src/lapi.c b/src/lapi.c
index fbfafa3..0a91c7d 100644
--- a/src/lapi.c
+++ b/src/lapi.c
@@ -106,7 +106,7 @@
     if (inuse > LUAI_MAXSTACK - n)  /* can grow without overflow? */
       res = 0;  /* no */
     else  /* try to grow stack */
-      res = (luaD_rawrunprotected(L, &growstack, &n) == LUA_OK);
+      res = (luaD_rawrunprotected(L, growstack, &n) == LUA_OK);
   }
   if (res && ci->top < L->top + n)
     ci->top = L->top + n;  /* adjust frame top */
diff --git a/src/lauxlib.c b/src/lauxlib.c
index 1c41d6a..3bb1ec0 100644
--- a/src/lauxlib.c
+++ b/src/lauxlib.c
@@ -954,7 +954,7 @@
 
 LUALIB_API lua_State *luaL_newstate (void) {
   lua_State *L = lua_newstate(l_alloc, NULL);
-  if (L) lua_atpanic(L, &panic);
+  if (L) lua_atpanic(L, panic);
   return L;
 }
 
diff --git a/src/liolib.c b/src/liolib.c
index 4dea396..d063f5a 100644
--- a/src/liolib.c
+++ b/src/liolib.c
@@ -228,7 +228,7 @@
 static LStream *newfile (lua_State *L) {
   LStream *p = newprefile(L);
   p->f = NULL;
-  p->closef = &io_fclose;
+  p->closef = io_fclose;
   return p;
 }
 
@@ -266,7 +266,7 @@
   const char *mode = luaL_optstring(L, 2, "r");
   LStream *p = newprefile(L);
   p->f = l_popen(L, filename, mode);
-  p->closef = &io_pclose;
+  p->closef = io_pclose;
   return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
 }
 
@@ -725,7 +725,7 @@
 */
 static int io_noclose (lua_State *L) {
   LStream *p = tolstream(L);
-  p->closef = &io_noclose;  /* keep file opened */
+  p->closef = io_noclose;  /* keep file opened */
   lua_pushnil(L);
   lua_pushliteral(L, "cannot close standard file");
   return 2;
@@ -736,7 +736,7 @@
                            const char *fname) {
   LStream *p = newprefile(L);
   p->f = f;
-  p->closef = &io_noclose;
+  p->closef = io_noclose;
   if (k != NULL) {
     lua_pushvalue(L, -1);
     lua_setfield(L, LUA_REGISTRYINDEX, k);  /* add file to registry */
diff --git a/src/lstate.c b/src/lstate.c
index ff6b02d..d0925aa 100644
--- a/src/lstate.c
+++ b/src/lstate.c
@@ -88,7 +88,7 @@
   addbuff(buff, p, L);  /* heap variable */
   addbuff(buff, p, &h);  /* local variable */
   addbuff(buff, p, luaO_nilobject);  /* global variable */
-  addbuff(buff, p, &lua_newstate);  /* public function */
+  addbuff(buff, p, lua_newstate);  /* public function */
   lua_assert(p == sizeof(buff));
   return luaS_hash(buff, p, h);
 }
diff --git a/src/lua.c b/src/lua.c
index 34a3900..f35ef55 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -599,7 +599,7 @@
     l_message(argv[0], "cannot create state: not enough memory");
     return EXIT_FAILURE;
   }
-  lua_pushcfunction(L, &pmain);  /* to call 'pmain' in protected mode */
+  lua_pushcfunction(L, pmain);  /* to call 'pmain' in protected mode */
   lua_pushinteger(L, argc);  /* 1st argument */
   lua_pushlightuserdata(L, argv); /* 2nd argument */
   status = lua_pcall(L, 2, 1, 0);  /* do the call */
diff --git a/src/luac.c b/src/luac.c
index c565f46..02d056d 100644
--- a/src/luac.c
+++ b/src/luac.c
@@ -197,7 +197,7 @@
  if (argc<=0) usage("no input files given");
  L=luaL_newstate();
  if (L==NULL) fatal("cannot create state: not enough memory");
- lua_pushcfunction(L,&pmain);
+ lua_pushcfunction(L,pmain);
  lua_pushinteger(L,argc);
  lua_pushlightuserdata(L,argv);
  if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));
-- 

Info 825: control flows into case/default without -fallthrough comment

lint recognizes the comment /* FALLTHROUGH */

diff --git a/src/lcode.c b/src/lcode.c
index 5e34624..9205cf5 100644
--- a/src/lcode.c
+++ b/src/lcode.c
@@ -573,8 +573,8 @@
     case VKFLT: {
       e->u.info = luaK_numberK(fs, e->u.nval);
       e->k = VK;
-      /* go through */
     }
+    /* FALLTHROUGH */
     case VK: {
      vk:
       if (e->u.info <= MAXINDEXRK)  /* constant fits in 'argC'? */
diff --git a/src/lgc.c b/src/lgc.c
index 8b95fb6..1e2d6e5 100644
--- a/src/lgc.c
+++ b/src/lgc.c
@@ -689,7 +689,7 @@
     case LUA_TUSERDATA: luaM_freemem(L, o, sizeudata(gco2u(o))); break;
     case LUA_TSHRSTR:
       luaS_remove(L, gco2ts(o));  /* remove it from hash table */
-      /* go through */
+      /* FALLTHROUGH */
     case LUA_TLNGSTR: {
       luaM_freemem(L, o, sizestring(gco2ts(o)));
       break;
diff --git a/src/llex.c b/src/llex.c
index 6e4a457..b223730 100644
--- a/src/llex.c
+++ b/src/llex.c
@@ -503,7 +503,7 @@
         }
         else if (sep == -1) return '[';
         else lexerror(ls, "invalid long string delimiter", TK_STRING);
-      }
+      } /* FALLTHROUGH */
       case '=': {
         next(ls);
         if (check_next1(ls, '=')) return TK_EQ;
diff --git a/src/lstrlib.c b/src/lstrlib.c
index a650b76..b7cb131 100644
--- a/src/lstrlib.c
+++ b/src/lstrlib.c
@@ -499,7 +499,7 @@
             }
             case '+':  /* 1 or more repetitions */
               s++;  /* 1 match already done */
-              /* go through */
+              /* FALLTHROUGH */
             case '*':  /* 0 or more repetitions */
               s = max_expand(ms, s, p, ep);
               break;
@@ -1249,7 +1249,7 @@
         totalsize += len + 1;
         break;
       }
-      case Kpadding: luaL_addchar(&b, LUA_PACKPADBYTE);  /* go through */
+      case Kpadding: luaL_addchar(&b, LUA_PACKPADBYTE);  /* FALLTHROUGH */
       case Kpaddalign: case Knop:
         arg--;  /* undo increment */
         break;
diff --git a/src/ltable.c b/src/ltable.c
index 38be005..8e9b3db 100644
--- a/src/ltable.c
+++ b/src/ltable.c
@@ -546,8 +546,8 @@
       lua_Integer k;
       if (numisinteger(fltvalue(key), &k)) /* index is int? */
         return luaH_getint(t, k);  /* use specialized version */
-      /* else go through */
     }
+    /* FALLTHROUGH */
     default: {
       Node *n = mainposition(t, key);
       for (;;) {  /* check whether 'key' is somewhere in the chain */
diff --git a/src/ltm.c b/src/ltm.c
index 25b46b1..19fe7d2 100644
--- a/src/ltm.c
+++ b/src/ltm.c
@@ -116,7 +116,7 @@
   if (!luaT_callbinTM(L, p1, p2, res, event)) {
     switch (event) {
       case TM_CONCAT:
-        luaG_concaterror(L, p1, p2);
+        luaG_concaterror(L, p1, p2); /* FALLTHROUGH */
       case TM_BAND: case TM_BOR: case TM_BXOR:
       case TM_SHL: case TM_SHR: case TM_BNOT: {
         lua_Number dummy;
@@ -124,8 +124,8 @@
           luaG_tointerror(L, p1, p2);
         else
           luaG_opinterror(L, p1, p2, "perform bitwise operation on");
-        /* else go through */
       }
+      /* FALLTHROUGH */
       default:
         luaG_opinterror(L, p1, p2, "perform arithmetic on");
     }
diff --git a/src/lua.c b/src/lua.c
index f35ef55..dfbbfc3 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -482,14 +482,14 @@
         args |= has_E;
         break;
       case 'i':
-        args |= has_i;  /* goes through  (-i implies -v) */
+        args |= has_i;  /* FALLTHROUGH  (-i implies -v) */
       case 'v':
         if (argv[i][2] != '\0')  /* extra characters after 1st? */
           return has_error;  /* invalid option */
         args |= has_v;
         break;
       case 'e':
-        args |= has_e;  /* go through */
+        args |= has_e;  /* FALLTHROUGH */
       case 'l':  /* both options need an argument */
         if (argv[i][2] == '\0') {  /* no concatenated argument? */
           i++;  /* try next 'argv' */
-- 

Info 834: Operator '-' followed by operator '+' is confusing.

Use parentheses.

diff --git a/src/lapi.c b/src/lapi.c
index 0a91c7d..2cceb49 100644
--- a/src/lapi.c
+++ b/src/lapi.c
@@ -159,7 +159,7 @@
 LUA_API int lua_absindex (lua_State *L, int idx) {
   return (idx > 0 || ispseudo(idx))
          ? idx
-         : cast_int(L->top - L->ci->func + idx);
+         : cast_int((L->top - L->ci->func) + idx);
 }
 
 
@@ -210,7 +210,7 @@
   p = index2addr(L, idx);  /* start of segment */
   api_checkstackindex(idx, p);
   api_check((n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'");
-  m = (n >= 0 ? t - n : p - n - 1);  /* end of prefix */
+  m = (n >= 0 ? t - n : (p - n) - 1);  /* end of prefix */
   reverse(L, p, m);  /* reverse the prefix with length 'n' */
   reverse(L, m + 1, t);  /* reverse the suffix */
   reverse(L, p, t);  /* reverse the entire segment */
diff --git a/src/lbaselib.c b/src/lbaselib.c
index a240395..5b600f5 100644
--- a/src/lbaselib.c
+++ b/src/lbaselib.c
@@ -55,7 +55,7 @@
     return NULL;
   do {
     int digit = (isdigit((unsigned char)*s)) ? *s - '0'
-                   : toupper((unsigned char)*s) - 'A' + 10;
+                   : toupper((unsigned char)*s) - ('A' - 10);
     if (digit >= base) return NULL;  /* invalid numeral */
     n = n * base + digit;
     s++;
diff --git a/src/lcode.c b/src/lcode.c
index 9205cf5..6bcd36a 100644
--- a/src/lcode.c
+++ b/src/lcode.c
@@ -793,7 +793,7 @@
 static void codeexpval (FuncState *fs, OpCode op,
                         expdesc *e1, expdesc *e2, int line) {
   lua_assert(op >= OP_ADD);
-  if (op <= OP_BNOT && constfolding(fs, op - OP_ADD + LUA_OPADD, e1, e2))
+  if (op <= OP_BNOT && constfolding(fs, (op - OP_ADD) + LUA_OPADD, e1, e2))
     return;  /* result has been folded */
   else {
     int o1, o2;
@@ -920,11 +920,11 @@
       break;
     }
     case OPR_EQ: case OPR_LT: case OPR_LE: {
-      codecomp(fs, cast(OpCode, op - OPR_EQ + OP_EQ), 1, e1, e2);
+      codecomp(fs, cast(OpCode, (op - OPR_EQ) + OP_EQ), 1, e1, e2);
       break;
     }
     case OPR_NE: case OPR_GT: case OPR_GE: {
-      codecomp(fs, cast(OpCode, op - OPR_NE + OP_EQ), 0, e1, e2);
+      codecomp(fs, cast(OpCode, (op - OPR_NE) + OP_EQ), 0, e1, e2);
       break;
     }
     default: lua_assert(0);
diff --git a/src/ldebug.c b/src/ldebug.c
index 6986bf0..7036f67 100644
--- a/src/ldebug.c
+++ b/src/ldebug.c
@@ -106,7 +106,7 @@
 
 static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
   int nparams = clLvalue(ci->func)->p->numparams;
-  if (n >= ci->u.l.base - ci->func - nparams)
+  if (n >= (ci->u.l.base - ci->func) - nparams)
     return NULL;  /* no such vararg */
   else {
     *pos = ci->func + nparams + n;
diff --git a/src/ldo.c b/src/ldo.c
index 5c9c7f5..d0555da 100644
--- a/src/ldo.c
+++ b/src/ldo.c
@@ -624,7 +624,7 @@
   else {
     if ((ci->u.c.k = k) != NULL)  /* is there a continuation? */
       ci->u.c.ctx = ctx;  /* save context */
-    ci->func = L->top - nresults - 1;  /* protect stack below results */
+    ci->func = (L->top - nresults) - 1;  /* protect stack below results */
     luaD_throw(L, LUA_YIELD);
   }
   lua_assert(ci->callstatus & CIST_HOOKED);  /* must be inside a hook */
diff --git a/src/llex.c b/src/llex.c
index b223730..4162662 100644
--- a/src/llex.c
+++ b/src/llex.c
@@ -567,7 +567,7 @@
                                   luaZ_bufflen(ls->buff));
           seminfo->ts = ts;
           if (isreserved(ts))  /* reserved word? */
-            return ts->extra - 1 + FIRST_RESERVED;
+            return (ts->extra - 1) + FIRST_RESERVED;
           else {
             return TK_NAME;
           }
diff --git a/src/llex.h b/src/llex.h
index afb40b5..d31f918 100644
--- a/src/llex.h
+++ b/src/llex.h
@@ -37,7 +37,7 @@
 };
 
 /* number of reserved words */
-#define NUM_RESERVED	(cast(int, TK_WHILE-FIRST_RESERVED+1))
+#define NUM_RESERVED	(cast(int, (TK_WHILE-FIRST_RESERVED)+1))
 
 
 typedef union {
diff --git a/src/lobject.c b/src/lobject.c
index 6a24aff..463c661 100644
--- a/src/lobject.c
+++ b/src/lobject.c
@@ -149,13 +149,13 @@
   }
   /* could not perform raw operation; try metamethod */
   lua_assert(L != NULL);  /* should not fail when folding (compile time) */
-  luaT_trybinTM(L, p1, p2, res, cast(TMS, op - LUA_OPADD + TM_ADD));
+  luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD));
 }
 
 
 int luaO_hexavalue (int c) {
   if (lisdigit(c)) return c - '0';
-  else return ltolower(c) - 'a' + 10;
+  else return ltolower(c) - ('a' - 10);
 }
 
 
@@ -290,7 +290,7 @@
   }
   else
     return 0;  /* conversion failed */
-  return (e - s + 1);  /* success; return string size */
+  return (e - s) + 1;  /* success; return string size */
 }
 
 
diff --git a/src/lstrlib.c b/src/lstrlib.c
index b7cb131..aac9c17 100644
--- a/src/lstrlib.c
+++ b/src/lstrlib.c
@@ -70,7 +70,7 @@
   if (start < 1) start = 1;
   if (end > (lua_Integer)l) end = l;
   if (start <= end)
-    lua_pushlstring(L, s + start - 1, (size_t)(end - start + 1));
+    lua_pushlstring(L, (s + start) - 1, (size_t)((end - start) + 1));
   else lua_pushliteral(L, "");
   return 1;
 }
@@ -82,7 +82,7 @@
   const char *s = luaL_checklstring(L, 1, &l);
   char *p = luaL_buffinitsize(L, &b, l);
   for (i = 0; i < l; i++)
-    p[i] = s[l - i - 1];
+    p[i] = s[(l - i) - 1];
   luaL_pushresultsize(&b, l);
   return 1;
 }
@@ -149,7 +149,7 @@
   if (posi < 1) posi = 1;
   if (pose > (lua_Integer)l) pose = l;
   if (posi > pose) return 0;  /* empty interval; return no values */
-  n = (int)(pose -  posi + 1);
+  n = (int)((pose -  posi) + 1);
   if (posi + n <= pose)  /* arithmetic overflow? */
     return luaL_error(L, "string slice too long");
   luaL_checkstack(L, n, "string slice too long");
@@ -554,7 +554,7 @@
     ptrdiff_t l = ms->capture[i].len;
     if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
     if (l == CAP_POSITION)
-      lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1);
+      lua_pushinteger(ms->L, (ms->capture[i].init - ms->src_init) + 1);
     else
       lua_pushlstring(ms->L, ms->capture[i].init, l);
   }
@@ -596,16 +596,16 @@
   /* explicit request or no special characters? */
   if (find && (lua_toboolean(L, 4) || nospecials(p, lp))) {
     /* do a plain search */
-    const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp);
+    const char *s2 = lmemfind((s + init) - 1, (ls - (size_t)init) + 1, p, lp);
     if (s2) {
-      lua_pushinteger(L, s2 - s + 1);
-      lua_pushinteger(L, s2 - s + lp);
+      lua_pushinteger(L, (s2 - s) + 1);
+      lua_pushinteger(L, (s2 - s) + lp);
       return 2;
     }
   }
   else {
     MatchState ms;
-    const char *s1 = s + init - 1;
+    const char *s1 = (s + init) - 1;
     int anchor = (*p == '^');
     if (anchor) {
       p++; lp--;  /* skip anchor character */
@@ -621,7 +621,7 @@
       lua_assert(ms.matchdepth == MAXCCALLS);
       if ((res=match(&ms, s1, p)) != NULL) {
         if (find) {
-          lua_pushinteger(L, s1 - s + 1);  /* start */
+          lua_pushinteger(L, (s1 - s) + 1);  /* start */
           lua_pushinteger(L, res - s);   /* end */
           return push_captures(&ms, NULL, 0) + 2;
         }
@@ -849,8 +849,8 @@
   if (isdigit(uchar(*p)))
     luaL_error(L, "invalid format (width or precision too long)");
   *(form++) = '%';
-  memcpy(form, strfrmt, (p - strfrmt + 1) * sizeof(char));
-  form += p - strfrmt + 1;
+  memcpy(form, strfrmt, ((p - strfrmt) + 1) * sizeof(char));
+  form += (p - strfrmt) + 1;
   *form = '\0';
   return p;
 }
@@ -1148,11 +1148,11 @@
   buff[islittle ? 0 : size - 1] = (char)(n & MC);  /* first byte */
   for (i = 1; i < size; i++) {
     n >>= NB;
-    buff[islittle ? i : size - 1 - i] = (char)(n & MC);
+    buff[islittle ? i : (size - 1) - i] = (char)(n & MC);
   }
   if (neg && size > SZINT) {  /* negative number need sign extension? */
     for (i = SZINT; i < size; i++)  /* correct extra bytes */
-      buff[islittle ? i : size - 1 - i] = (char)MC;
+      buff[islittle ? i : (size - 1) - i] = (char)MC;
   }
   luaL_addsize(b, size);  /* add result to buffer */
 }
@@ -1300,7 +1300,7 @@
   int limit = (size  <= SZINT) ? size : SZINT;
   for (i = limit - 1; i >= 0; i--) {
     res <<= NB;
-    res |= (lua_Unsigned)(unsigned char)str[islittle ? i : size - 1 - i];
+    res |= (lua_Unsigned)(unsigned char)str[islittle ? i : (size - 1) - i];
   }
   if (size < SZINT) {  /* real size smaller than lua_Integer? */
     if (issigned) {  /* needs sign extension? */
@@ -1311,7 +1311,7 @@
   else if (size > SZINT) {  /* must check unread bytes */
     int mask = (!issigned || (lua_Integer)res >= 0) ? 0 : MC;
     for (i = limit; i < size; i++) {
-      if ((unsigned char)str[islittle ? i : size - 1 - i] != mask)
+      if ((unsigned char)str[islittle ? i : (size - 1) - i] != mask)
         luaL_error(L, "%d-byte integer does not fit into Lua Integer", size);
     }
   }
diff --git a/src/ltablib.c b/src/ltablib.c
index 8f78afb..5576904 100644
--- a/src/ltablib.c
+++ b/src/ltablib.c
@@ -134,7 +134,7 @@
     ta.seti = (luaL_getmetafield(L, tt, "__newindex") == LUA_TNIL)
       ? (luaL_checktype(L, tt, LUA_TTABLE), lua_rawseti)
       : lua_seti;
-    n = e - f + 1;  /* number of elements to move */
+    n = (e - f) + 1;  /* number of elements to move */
     if (t > f) {
       for (i = n - 1; i >= 0; i--) {
         (*ta.geti)(L, 1, f + i);
diff --git a/src/luac.c b/src/luac.c
index 02d056d..39ca5af 100644
--- a/src/luac.c
+++ b/src/luac.c
@@ -148,7 +148,7 @@
   f=toproto(L,-1);
   for (i=0; i<n; i++)
   {
-   f->p[i]=toproto(L,i-n-1);
+   f->p[i]=toproto(L,(i-n)-1);
    if (f->p[i]->sizeupvalues>0) f->p[i]->upvalues[0].instack=0;
   }
   f->sizelineinfo=0;
diff --git a/src/lutf8lib.c b/src/lutf8lib.c
index be4f087..343deb4 100644
--- a/src/lutf8lib.c
+++ b/src/lutf8lib.c
@@ -106,7 +106,7 @@
   luaL_argcheck(L, posi >= 1, 2, "out of range");
   luaL_argcheck(L, pose <= (lua_Integer)len, 3, "out of range");
   if (posi > pose) return 0;  /* empty interval; return no values */
-  n = (int)(pose -  posi + 1);
+  n = (int)((pose -  posi) + 1);
   if (posi + n <= pose)  /* (lua_Integer -> int) overflow? */
     return luaL_error(L, "string slice too long");
   luaL_checkstack(L, n, "string slice too long");
diff --git a/src/lvm.c b/src/lvm.c
index 2ac1b02..02c40b0 100644
--- a/src/lvm.c
+++ b/src/lvm.c
@@ -376,8 +376,8 @@
       char *buffer;
       int i;
       /* collect total length */
-      for (i = 1; i < total && tostring(L, top-i-1); i++) {
-        size_t l = tsvalue(top-i-1)->len;
+      for (i = 1; i < total && tostring(L, (top-i)-1); i++) {
+        size_t l = tsvalue((top-i)-1)->len;
         if (l >= (MAX_SIZE/sizeof(char)) - tl)
           luaG_runerror(L, "string length overflow");
         tl += l;
@@ -566,7 +566,7 @@
     case OP_CONCAT: {
       StkId top = L->top - 1;  /* top when 'luaT_trybinTM' was called */
       int b = GETARG_B(inst);      /* first element to concatenate */
-      int total = cast_int(top - 1 - (base + b));  /* yet to concatenate */
+      int total = cast_int((top - 1) - (base + b));  /* yet to concatenate */
       setobj2s(L, top - 2, top);  /* put TM result in proper position */
       if (total > 1) {  /* are there elements to concat? */
         L->top = top - 1;  /* top is one after last element (at top-2) */
@@ -926,7 +926,7 @@
         int c = GETARG_C(i);
         StkId rb;
         L->top = base + c + 1;  /* mark the end of concat operands */
-        Protect(luaV_concat(L, c - b + 1));
+        Protect(luaV_concat(L, (c - b) + 1));
         ra = RA(i);  /* 'luav_concat' may invoke TMs and move the stack */
         rb = b + base;
         setobjs2s(L, ra, rb);
@@ -1153,7 +1153,7 @@
       vmcase(OP_VARARG) {
         int b = GETARG_B(i) - 1;
         int j;
-        int n = cast_int(base - ci->func) - cl->p->numparams - 1;
+        int n = (cast_int(base - ci->func) - cl->p->numparams) - 1;
         if (b < 0) {  /* B == 0? */
           b = n;  /* get all var. arguments */
           Protect(luaD_checkstack(L, n));
@@ -1162,7 +1162,7 @@
         }
         for (j = 0; j < b; j++) {
           if (j < n) {
-            setobjs2s(L, ra + j, base - n + j);
+            setobjs2s(L, ra + j, (base - n) + j);
           }
           else {
             setnilvalue(ra + j);
-- 

lutf8lib.c: Info 843: Variable could be declared as const

--- Module:   src/lutf8lib.c (C)
_
}
src/lutf8lib.c  62  Info 843: Variable 'limits' (line 40) could be declared as const
src/lutf8lib.c  40  Info 830: Location cited in prior message

    --- Wrap-up for Module: src/lutf8lib.c

Info 843: Variable 'funcs' (line 237, file src/lutf8lib.c) could be declared as const
src/lutf8lib.c  237  Info 830: Location cited in prior message

diff --git a/src/lutf8lib.c b/src/lutf8lib.c
index 343deb4..0d24be2 100644
--- a/src/lutf8lib.c
+++ b/src/lutf8lib.c
@@ -37,7 +37,7 @@
 ** Decode one UTF-8 sequence, returning NULL if byte sequence is invalid.
 */
 static const char *utf8_decode (const char *o, int *val) {
-  static unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF};
+  static const unsigned int limits[] = {0xFF, 0x7F, 0x7FF, 0xFFFF};
   const unsigned char *s = (const unsigned char *)o;
   unsigned int c = s[0];
   unsigned int res = 0;  /* final result */
@@ -234,7 +234,7 @@
 #define UTF8PATT	"[\0-\x7F\xC2-\xF4][\x80-\xBF]*"
 
 
-static struct luaL_Reg funcs[] = {
+static const struct luaL_Reg funcs[] = {
   {"offset", byteoffset},
   {"codepoint", codepoint},
   {"char", utfchar},
-- 

ldump.c: Info 866: Unusual use of '&' in argument to sizeof

remove one level of macro

--- Module:   src/ldump.c (C)
              _
#... ((&x)[0]),D)
#... or(&x,1,D)
  DumpVar(x, D);
src/ldump.c  54  Info 866: Unusual use of '&' in argument to sizeof
              _
#... ((&x)[0]),D)
#... or(&x,1,D)
  DumpVar(x, D);
src/ldump.c  59  Info 866: Unusual use of '&' in argument to sizeof
              _
#... ((&x)[0]),D)
#... or(&x,1,D)
  DumpVar(x, D);
src/ldump.c  64  Info 866: Unusual use of '&' in argument to sizeof
              _
#... ((&x)[0]),D)
#... or(&x,1,D)
  DumpVar(x, D);
src/ldump.c  69  Info 866: Unusual use of '&' in argument to sizeof
                     _
#... zeof((&size)[0]),D)
#... Vector(&size,1,D)
      DumpVar(size, D);
src/ldump.c  82  Info 866: Unusual use of '&' in argument to sizeof

diff --git a/src/ldump.c b/src/ldump.c
index b6c7114..bef9fd0 100644
--- a/src/ldump.c
+++ b/src/ldump.c
@@ -46,7 +46,7 @@
 }
 
 
-#define DumpVar(x,D)		DumpVector(&x,1,D)
+#define DumpVar(x,D)		DumpBlock(&x,sizeof(x),D)
 
 
 static void DumpByte (int y, DumpState *D) {
-- 

lundump.c: Info 866: Unusual use of '&' in argument to sizeof

remove one level of macro

--- Module:   src/lundump.c (C)
              _
#... or(S,&x,1)
  LoadVar(S, x);
src/lundump.c  63  Info 866: Unusual use of '&' in argument to sizeof
              _
#... or(S,&x,1)
  LoadVar(S, x);
src/lundump.c  70  Info 866: Unusual use of '&' in argument to sizeof
              _
#... or(S,&x,1)
  LoadVar(S, x);
src/lundump.c  77  Info 866: Unusual use of '&' in argument to sizeof
              _
#... or(S,&x,1)
  LoadVar(S, x);
src/lundump.c  84  Info 866: Unusual use of '&' in argument to sizeof
                   _
#... ctor(S,&size,1)
    LoadVar(S, size);
src/lundump.c  92  Info 866: Unusual use of '&' in argument to sizeof

diff --git a/src/lundump.c b/src/lundump.c
index 510f325..a1e3d61 100644
--- a/src/lundump.c
+++ b/src/lundump.c
@@ -55,7 +55,7 @@
 }
 
 
-#define LoadVar(S,x)		LoadVector(S,&x,1)
+#define LoadVar(S,x)		LoadBlock(S,&x,sizeof(x))
 
 
 static lu_byte LoadByte (LoadState *S) {
-- 

Note 910: Implicit conversion (return) from 0 to pointer

replace O by NULL

diff --git a/src/ldebug.c b/src/ldebug.c
index 7036f67..6803037 100644
--- a/src/ldebug.c
+++ b/src/ldebug.c
@@ -151,7 +151,7 @@
       name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);
   }
   else {  /* active function; get information through 'ar' */
-    StkId pos = 0;  /* to avoid warnings */
+    StkId pos = NULL;  /* to avoid warnings */
     name = findlocal(L, ar->i_ci, n, &pos);
     if (name) {
       setobj2s(L, L->top, pos);
@@ -164,7 +164,7 @@
 
 
 LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
-  StkId pos = 0;  /* to avoid warnings */
+  StkId pos = NULL;  /* to avoid warnings */
   const char *name = findlocal(L, ar->i_ci, n, &pos);
   lua_lock(L);
   if (name) {
diff --git a/src/lobject.c b/src/lobject.c
index 463c661..3c2447a 100644
--- a/src/lobject.c
+++ b/src/lobject.c
@@ -244,7 +244,7 @@
     *result = lua_strx2number(s, &endptr);
   else
     *result = lua_str2number(s, &endptr);
-  if (endptr == s) return 0;  /* nothing recognized */
+  if (endptr == s) return NULL;  /* nothing recognized */
   while (lisspace(cast_uchar(*endptr))) endptr++;
   return (*endptr == '\0' ? endptr : NULL);  /* OK if no trailing characters */
 }
--