aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-06-12 11:21:18 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-06-12 11:21:18 -0300
commitb1203e036dceeb57947e88793cc7f7eb238542a0 (patch)
tree0f408f328a7c2471179696f56a30cae38a70654e
parent92a0d4c67fb962679559c6bce67ab57280a99f3e (diff)
downloadlua-b1203e036dceeb57947e88793cc7f7eb238542a0.tar.gz
lua-b1203e036dceeb57947e88793cc7f7eb238542a0.tar.bz2
lua-b1203e036dceeb57947e88793cc7f7eb238542a0.zip
'posrelat' avoids problems with -(-2^31)
-rw-r--r--lstrlib.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 338d81ec..6727990d 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.139 2007/11/12 14:10:09 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.140 2008/04/14 15:54:59 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*/
@@ -36,7 +36,7 @@ static int str_len (lua_State *L) {
36/* translate a relative string position: negative means back from end */ 36/* translate a relative string position: negative means back from end */
37static size_t posrelat (ptrdiff_t pos, size_t len) { 37static size_t posrelat (ptrdiff_t pos, size_t len) {
38 if (pos >= 0) return (size_t)pos; 38 if (pos >= 0) return (size_t)pos;
39 else if ((size_t)-pos > len) return 0; 39 else if (pos == -pos || (size_t)-pos > len) return 0;
40 else return len - ((size_t)-pos) + 1; 40 else return len - ((size_t)-pos) + 1;
41} 41}
42 42