lua

A copy of the Lua development repository
Log | Files | Refs | README

commit b1203e036dceeb57947e88793cc7f7eb238542a0
parent 92a0d4c67fb962679559c6bce67ab57280a99f3e
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Thu, 12 Jun 2008 11:20:55 -0300

'posrelat' avoids problems with -(-2^31)

Diffstat:
Mlstrlib.c | 4++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lstrlib.c b/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.139 2007/11/12 14:10:09 roberto Exp roberto $ +** $Id: lstrlib.c,v 1.140 2008/04/14 15:54:59 roberto Exp roberto $ ** Standard library for string operations and pattern-matching ** See Copyright Notice in lua.h */ @@ -36,7 +36,7 @@ static int str_len (lua_State *L) { /* translate a relative string position: negative means back from end */ static size_t posrelat (ptrdiff_t pos, size_t len) { if (pos >= 0) return (size_t)pos; - else if ((size_t)-pos > len) return 0; + else if (pos == -pos || (size_t)-pos > len) return 0; else return len - ((size_t)-pos) + 1; }