aboutsummaryrefslogtreecommitdiff
path: root/ltablib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-04-07 15:43:00 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-04-07 15:43:00 -0300
commitffdca3522e757f0203b7bdbe5bccb0ae826bfd81 (patch)
treeb6dda09ab722b75e3476bc4c926094ace501f7c7 /ltablib.c
parent4d7469b610814d2ebb1e89aebebdeb68abfe7f4e (diff)
downloadlua-ffdca3522e757f0203b7bdbe5bccb0ae826bfd81.tar.gz
lua-ffdca3522e757f0203b7bdbe5bccb0ae826bfd81.tar.bz2
lua-ffdca3522e757f0203b7bdbe5bccb0ae826bfd81.zip
'table.sort' detects invalid order function before calling it
for nil elements
Diffstat (limited to 'ltablib.c')
-rw-r--r--ltablib.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/ltablib.c b/ltablib.c
index e98188c4..ab83c0c8 100644
--- a/ltablib.c
+++ b/ltablib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltablib.c,v 1.42 2007/11/26 16:57:33 roberto Exp roberto $ 2** $Id: ltablib.c,v 1.43 2008/02/14 16:03:27 roberto Exp roberto $
3** Library for Table Manipulation 3** Library for Table Manipulation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -215,12 +215,12 @@ static void auxsort (lua_State *L, int l, int u) {
215 for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */ 215 for (;;) { /* invariant: a[l..i] <= P <= a[j..u] */
216 /* repeat ++i until a[i] >= P */ 216 /* repeat ++i until a[i] >= P */
217 while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) { 217 while (lua_rawgeti(L, 1, ++i), sort_comp(L, -1, -2)) {
218 if (i>u) luaL_error(L, "invalid order function for sorting"); 218 if (i>=u) luaL_error(L, "invalid order function for sorting");
219 lua_pop(L, 1); /* remove a[i] */ 219 lua_pop(L, 1); /* remove a[i] */
220 } 220 }
221 /* repeat --j until a[j] <= P */ 221 /* repeat --j until a[j] <= P */
222 while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) { 222 while (lua_rawgeti(L, 1, --j), sort_comp(L, -3, -1)) {
223 if (j<l) luaL_error(L, "invalid order function for sorting"); 223 if (j<=l) luaL_error(L, "invalid order function for sorting");
224 lua_pop(L, 1); /* remove a[j] */ 224 lua_pop(L, 1); /* remove a[j] */
225 } 225 }
226 if (j<i) { 226 if (j<i) {