summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lapi.c4
-rw-r--r--lbaselib.c4
-rw-r--r--lcode.c10
-rw-r--r--ldebug.c8
-rw-r--r--llex.c12
-rw-r--r--lobject.c10
-rw-r--r--lstrlib.c24
7 files changed, 37 insertions, 35 deletions
diff --git a/lapi.c b/lapi.c
index 7bbdf70e..595a4512 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.246 2015/02/11 18:47:22 roberto Exp $ 2** $Id: lapi.c,v 2.247 2015/03/06 19:49:50 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -160,7 +160,7 @@ LUA_API const lua_Number *lua_version (lua_State *L) {
160LUA_API int lua_absindex (lua_State *L, int idx) { 160LUA_API int lua_absindex (lua_State *L, int idx) {
161 return (idx > 0 || ispseudo(idx)) 161 return (idx > 0 || ispseudo(idx))
162 ? idx 162 ? idx
163 : cast_int(L->top - L->ci->func + idx); 163 : cast_int(L->top - L->ci->func) + idx;
164} 164}
165 165
166 166
diff --git a/lbaselib.c b/lbaselib.c
index f3b0a577..40caaa94 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.308 2014/12/08 15:26:55 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.309 2014/12/10 12:26:42 roberto Exp roberto $
3** Basic library 3** Basic library
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -55,7 +55,7 @@ static const char *b_str2int (const char *s, int base, lua_Integer *pn) {
55 return NULL; 55 return NULL;
56 do { 56 do {
57 int digit = (isdigit((unsigned char)*s)) ? *s - '0' 57 int digit = (isdigit((unsigned char)*s)) ? *s - '0'
58 : toupper((unsigned char)*s) - 'A' + 10; 58 : (toupper((unsigned char)*s) - 'A') + 10;
59 if (digit >= base) return NULL; /* invalid numeral */ 59 if (digit >= base) return NULL; /* invalid numeral */
60 n = n * base + digit; 60 n = n * base + digit;
61 s++; 61 s++;
diff --git a/lcode.c b/lcode.c
index eae7e7d7..280d91ea 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.98 2014/12/19 13:36:32 roberto Exp roberto $ 2** $Id: lcode.c,v 2.99 2014/12/29 16:49:25 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -573,8 +573,8 @@ int luaK_exp2RK (FuncState *fs, expdesc *e) {
573 case VKFLT: { 573 case VKFLT: {
574 e->u.info = luaK_numberK(fs, e->u.nval); 574 e->u.info = luaK_numberK(fs, e->u.nval);
575 e->k = VK; 575 e->k = VK;
576 /* go through */
577 } 576 }
577 /* FALLTHROUGH */
578 case VK: { 578 case VK: {
579 vk: 579 vk:
580 if (e->u.info <= MAXINDEXRK) /* constant fits in 'argC'? */ 580 if (e->u.info <= MAXINDEXRK) /* constant fits in 'argC'? */
@@ -793,7 +793,7 @@ static int constfolding (FuncState *fs, int op, expdesc *e1, expdesc *e2) {
793static void codeexpval (FuncState *fs, OpCode op, 793static void codeexpval (FuncState *fs, OpCode op,
794 expdesc *e1, expdesc *e2, int line) { 794 expdesc *e1, expdesc *e2, int line) {
795 lua_assert(op >= OP_ADD); 795 lua_assert(op >= OP_ADD);
796 if (op <= OP_BNOT && constfolding(fs, op - OP_ADD + LUA_OPADD, e1, e2)) 796 if (op <= OP_BNOT && constfolding(fs, (op - OP_ADD) + LUA_OPADD, e1, e2))
797 return; /* result has been folded */ 797 return; /* result has been folded */
798 else { 798 else {
799 int o1, o2; 799 int o1, o2;
@@ -920,11 +920,11 @@ void luaK_posfix (FuncState *fs, BinOpr op,
920 break; 920 break;
921 } 921 }
922 case OPR_EQ: case OPR_LT: case OPR_LE: { 922 case OPR_EQ: case OPR_LT: case OPR_LE: {
923 codecomp(fs, cast(OpCode, op - OPR_EQ + OP_EQ), 1, e1, e2); 923 codecomp(fs, cast(OpCode, (op - OPR_EQ) + OP_EQ), 1, e1, e2);
924 break; 924 break;
925 } 925 }
926 case OPR_NE: case OPR_GT: case OPR_GE: { 926 case OPR_NE: case OPR_GT: case OPR_GE: {
927 codecomp(fs, cast(OpCode, op - OPR_NE + OP_EQ), 0, e1, e2); 927 codecomp(fs, cast(OpCode, (op - OPR_NE) + OP_EQ), 0, e1, e2);
928 break; 928 break;
929 } 929 }
930 default: lua_assert(0); 930 default: lua_assert(0);
diff --git a/ldebug.c b/ldebug.c
index 86ee7dae..6e4cdb35 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.112 2015/03/06 19:49:50 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.113 2015/03/11 16:10:41 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -126,7 +126,7 @@ static const char *upvalname (Proto *p, int uv) {
126 126
127static const char *findvararg (CallInfo *ci, int n, StkId *pos) { 127static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
128 int nparams = clLvalue(ci->func)->p->numparams; 128 int nparams = clLvalue(ci->func)->p->numparams;
129 if (n >= ci->u.l.base - ci->func - nparams) 129 if (n >= cast_int(ci->u.l.base - ci->func) - nparams)
130 return NULL; /* no such vararg */ 130 return NULL; /* no such vararg */
131 else { 131 else {
132 *pos = ci->func + nparams + n; 132 *pos = ci->func + nparams + n;
@@ -172,7 +172,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
172 name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0); 172 name = luaF_getlocalname(clLvalue(L->top - 1)->p, n, 0);
173 } 173 }
174 else { /* active function; get information through 'ar' */ 174 else { /* active function; get information through 'ar' */
175 StkId pos = 0; /* to avoid warnings */ 175 StkId pos = NULL; /* to avoid warnings */
176 name = findlocal(L, ar->i_ci, n, &pos); 176 name = findlocal(L, ar->i_ci, n, &pos);
177 if (name) { 177 if (name) {
178 setobj2s(L, L->top, pos); 178 setobj2s(L, L->top, pos);
@@ -186,7 +186,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
186 186
187 187
188LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { 188LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
189 StkId pos = 0; /* to avoid warnings */ 189 StkId pos = NULL; /* to avoid warnings */
190 const char *name; 190 const char *name;
191 lua_lock(L); 191 lua_lock(L);
192 swapextra(L); 192 swapextra(L);
diff --git a/llex.c b/llex.c
index 8a6ac108..0c3eb4dd 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 2.89 2014/11/14 16:06:09 roberto Exp roberto $ 2** $Id: llex.c,v 2.90 2015/03/03 18:17:04 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -283,8 +283,9 @@ static int read_numeral (LexState *ls, SemInfo *seminfo) {
283 283
284 284
285/* 285/*
286** skip a sequence '[=*[' or ']=*]' and return its number of '='s or 286** skip a sequence '[=*[' or ']=*]'; if sequence is wellformed, return
287** -1 if sequence is malformed 287** its number of '='s; otherwise, return a negative number (-1 iff there
288** are no '='s after initial bracket)
288*/ 289*/
289static int skip_sep (LexState *ls) { 290static int skip_sep (LexState *ls) {
290 int count = 0; 291 int count = 0;
@@ -501,8 +502,9 @@ static int llex (LexState *ls, SemInfo *seminfo) {
501 read_long_string(ls, seminfo, sep); 502 read_long_string(ls, seminfo, sep);
502 return TK_STRING; 503 return TK_STRING;
503 } 504 }
504 else if (sep == -1) return '['; 505 else if (sep != -1) /* '[=...' missing second bracket */
505 else lexerror(ls, "invalid long string delimiter", TK_STRING); 506 lexerror(ls, "invalid long string delimiter", TK_STRING);
507 return '[';
506 } 508 }
507 case '=': { 509 case '=': {
508 next(ls); 510 next(ls);
diff --git a/lobject.c b/lobject.c
index 60d1f3d9..3b9bde60 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 2.101 2014/12/26 14:43:45 roberto Exp roberto $ 2** $Id: lobject.c,v 2.102 2015/02/05 17:15:33 roberto Exp roberto $
3** Some generic functions over Lua objects 3** Some generic functions over Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -150,13 +150,13 @@ void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2,
150 } 150 }
151 /* could not perform raw operation; try metamethod */ 151 /* could not perform raw operation; try metamethod */
152 lua_assert(L != NULL); /* should not fail when folding (compile time) */ 152 lua_assert(L != NULL); /* should not fail when folding (compile time) */
153 luaT_trybinTM(L, p1, p2, res, cast(TMS, op - LUA_OPADD + TM_ADD)); 153 luaT_trybinTM(L, p1, p2, res, cast(TMS, (op - LUA_OPADD) + TM_ADD));
154} 154}
155 155
156 156
157int luaO_hexavalue (int c) { 157int luaO_hexavalue (int c) {
158 if (lisdigit(c)) return c - '0'; 158 if (lisdigit(c)) return c - '0';
159 else return ltolower(c) - 'a' + 10; 159 else return (ltolower(c) - 'a') + 10;
160} 160}
161 161
162 162
@@ -243,7 +243,7 @@ static const char *l_str2d (const char *s, lua_Number *result) {
243 *result = lua_strx2number(s, &endptr); 243 *result = lua_strx2number(s, &endptr);
244 else 244 else
245 *result = lua_str2number(s, &endptr); 245 *result = lua_str2number(s, &endptr);
246 if (endptr == s) return 0; /* nothing recognized */ 246 if (endptr == s) return NULL; /* nothing recognized */
247 while (lisspace(cast_uchar(*endptr))) endptr++; 247 while (lisspace(cast_uchar(*endptr))) endptr++;
248 return (*endptr == '\0' ? endptr : NULL); /* OK if no trailing characters */ 248 return (*endptr == '\0' ? endptr : NULL); /* OK if no trailing characters */
249} 249}
@@ -289,7 +289,7 @@ size_t luaO_str2num (const char *s, TValue *o) {
289 } 289 }
290 else 290 else
291 return 0; /* conversion failed */ 291 return 0; /* conversion failed */
292 return (e - s + 1); /* success; return string size */ 292 return (e - s) + 1; /* success; return string size */
293} 293}
294 294
295 295
diff --git a/lstrlib.c b/lstrlib.c
index 28c2bf28..3fc5be98 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.225 2015/02/05 17:50:24 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.226 2015/02/09 18:05:46 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -70,7 +70,7 @@ static int str_sub (lua_State *L) {
70 if (start < 1) start = 1; 70 if (start < 1) start = 1;
71 if (end > (lua_Integer)l) end = l; 71 if (end > (lua_Integer)l) end = l;
72 if (start <= end) 72 if (start <= end)
73 lua_pushlstring(L, s + start - 1, (size_t)(end - start + 1)); 73 lua_pushlstring(L, s + start - 1, (size_t)(end - start) + 1);
74 else lua_pushliteral(L, ""); 74 else lua_pushliteral(L, "");
75 return 1; 75 return 1;
76} 76}
@@ -149,9 +149,9 @@ static int str_byte (lua_State *L) {
149 if (posi < 1) posi = 1; 149 if (posi < 1) posi = 1;
150 if (pose > (lua_Integer)l) pose = l; 150 if (pose > (lua_Integer)l) pose = l;
151 if (posi > pose) return 0; /* empty interval; return no values */ 151 if (posi > pose) return 0; /* empty interval; return no values */
152 n = (int)(pose - posi + 1); 152 if (pose - posi >= INT_MAX) /* arithmetic overflow? */
153 if (posi + n <= pose) /* arithmetic overflow? */
154 return luaL_error(L, "string slice too long"); 153 return luaL_error(L, "string slice too long");
154 n = (int)(pose - posi) + 1;
155 luaL_checkstack(L, n, "string slice too long"); 155 luaL_checkstack(L, n, "string slice too long");
156 for (i=0; i<n; i++) 156 for (i=0; i<n; i++)
157 lua_pushinteger(L, uchar(s[posi+i-1])); 157 lua_pushinteger(L, uchar(s[posi+i-1]));
@@ -499,7 +499,7 @@ static const char *match (MatchState *ms, const char *s, const char *p) {
499 } 499 }
500 case '+': /* 1 or more repetitions */ 500 case '+': /* 1 or more repetitions */
501 s++; /* 1 match already done */ 501 s++; /* 1 match already done */
502 /* go through */ 502 /* FALLTHROUGH */
503 case '*': /* 0 or more repetitions */ 503 case '*': /* 0 or more repetitions */
504 s = max_expand(ms, s, p, ep); 504 s = max_expand(ms, s, p, ep);
505 break; 505 break;
@@ -554,7 +554,7 @@ static void push_onecapture (MatchState *ms, int i, const char *s,
554 ptrdiff_t l = ms->capture[i].len; 554 ptrdiff_t l = ms->capture[i].len;
555 if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture"); 555 if (l == CAP_UNFINISHED) luaL_error(ms->L, "unfinished capture");
556 if (l == CAP_POSITION) 556 if (l == CAP_POSITION)
557 lua_pushinteger(ms->L, ms->capture[i].init - ms->src_init + 1); 557 lua_pushinteger(ms->L, (ms->capture[i].init - ms->src_init) + 1);
558 else 558 else
559 lua_pushlstring(ms->L, ms->capture[i].init, l); 559 lua_pushlstring(ms->L, ms->capture[i].init, l);
560 } 560 }
@@ -598,8 +598,8 @@ static int str_find_aux (lua_State *L, int find) {
598 /* do a plain search */ 598 /* do a plain search */
599 const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp); 599 const char *s2 = lmemfind(s + init - 1, ls - (size_t)init + 1, p, lp);
600 if (s2) { 600 if (s2) {
601 lua_pushinteger(L, s2 - s + 1); 601 lua_pushinteger(L, (s2 - s) + 1);
602 lua_pushinteger(L, s2 - s + lp); 602 lua_pushinteger(L, (s2 - s) + lp);
603 return 2; 603 return 2;
604 } 604 }
605 } 605 }
@@ -621,7 +621,7 @@ static int str_find_aux (lua_State *L, int find) {
621 lua_assert(ms.matchdepth == MAXCCALLS); 621 lua_assert(ms.matchdepth == MAXCCALLS);
622 if ((res=match(&ms, s1, p)) != NULL) { 622 if ((res=match(&ms, s1, p)) != NULL) {
623 if (find) { 623 if (find) {
624 lua_pushinteger(L, s1 - s + 1); /* start */ 624 lua_pushinteger(L, (s1 - s) + 1); /* start */
625 lua_pushinteger(L, res - s); /* end */ 625 lua_pushinteger(L, res - s); /* end */
626 return push_captures(&ms, NULL, 0) + 2; 626 return push_captures(&ms, NULL, 0) + 2;
627 } 627 }
@@ -935,8 +935,8 @@ static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
935 if (isdigit(uchar(*p))) 935 if (isdigit(uchar(*p)))
936 luaL_error(L, "invalid format (width or precision too long)"); 936 luaL_error(L, "invalid format (width or precision too long)");
937 *(form++) = '%'; 937 *(form++) = '%';
938 memcpy(form, strfrmt, (p - strfrmt + 1) * sizeof(char)); 938 memcpy(form, strfrmt, ((p - strfrmt) + 1) * sizeof(char));
939 form += p - strfrmt + 1; 939 form += (p - strfrmt) + 1;
940 *form = '\0'; 940 *form = '\0';
941 return p; 941 return p;
942} 942}
@@ -1335,7 +1335,7 @@ static int str_pack (lua_State *L) {
1335 totalsize += len + 1; 1335 totalsize += len + 1;
1336 break; 1336 break;
1337 } 1337 }
1338 case Kpadding: luaL_addchar(&b, LUA_PACKPADBYTE); /* go through */ 1338 case Kpadding: luaL_addchar(&b, LUA_PACKPADBYTE); /* FALLTHROUGH */
1339 case Kpaddalign: case Knop: 1339 case Kpaddalign: case Knop:
1340 arg--; /* undo increment */ 1340 arg--; /* undo increment */
1341 break; 1341 break;