aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--llex.c9
-rw-r--r--lobject.c13
-rw-r--r--lobject.h4
-rw-r--r--lvm.c4
4 files changed, 17 insertions, 13 deletions
diff --git a/llex.c b/llex.c
index 22a83ff1..5a742cf6 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 2.40 2010/10/25 12:24:36 roberto Exp roberto $ 2** $Id: llex.c,v 2.41 2010/11/18 18:38:44 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*/
@@ -200,6 +200,9 @@ static void buffreplace (LexState *ls, char from, char to) {
200#define getlocaledecpoint() (localeconv()->decimal_point[0]) 200#define getlocaledecpoint() (localeconv()->decimal_point[0])
201#endif 201#endif
202 202
203
204#define buff2d(b,e) luaO_str2d(luaZ_buffer(b), luaZ_bufflen(b) - 1, e)
205
203/* 206/*
204** in case of format error, try to change decimal point separator to 207** in case of format error, try to change decimal point separator to
205** the one defined in the current locale and check again 208** the one defined in the current locale and check again
@@ -208,7 +211,7 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) {
208 char old = ls->decpoint; 211 char old = ls->decpoint;
209 ls->decpoint = getlocaledecpoint(); 212 ls->decpoint = getlocaledecpoint();
210 buffreplace(ls, old, ls->decpoint); /* try new decimal separator */ 213 buffreplace(ls, old, ls->decpoint); /* try new decimal separator */
211 if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { 214 if (!buff2d(ls->buff, &seminfo->r)) {
212 /* format error with correct decimal point: no more options */ 215 /* format error with correct decimal point: no more options */
213 buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ 216 buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */
214 lexerror(ls, "malformed number", TK_NUMBER); 217 lexerror(ls, "malformed number", TK_NUMBER);
@@ -226,7 +229,7 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) {
226 } while (lislalnum(ls->current) || ls->current == '.'); 229 } while (lislalnum(ls->current) || ls->current == '.');
227 save(ls, '\0'); 230 save(ls, '\0');
228 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ 231 buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */
229 if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */ 232 if (!buff2d(ls->buff, &seminfo->r)) /* format error? */
230 trydecpoint(ls, seminfo); /* try to update decimal point separator */ 233 trydecpoint(ls, seminfo); /* try to update decimal point separator */
231} 234}
232 235
diff --git a/lobject.c b/lobject.c
index b3bacc08..598520ac 100644
--- a/lobject.c
+++ b/lobject.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.c,v 2.42 2010/10/29 11:13:14 roberto Exp roberto $ 2** $Id: lobject.c,v 2.43 2010/10/29 15:54:55 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*/
@@ -106,19 +106,20 @@ lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2) {
106} 106}
107 107
108 108
109static int checkend (const char *s, const char *endptr) { 109static int checkend (const char *s, const char *e, const char *endptr) {
110 if (endptr == s) return 0; /* no characters converted */ 110 if (endptr == s) return 0; /* no characters converted */
111 while (lisspace(cast(unsigned char, *endptr))) endptr++; 111 while (lisspace(cast(unsigned char, *endptr))) endptr++;
112 return (*endptr == '\0'); /* OK if no trailing characters */ 112 return (endptr == e); /* OK if no trailing characters */
113} 113}
114 114
115 115
116int luaO_str2d (const char *s, lua_Number *result) { 116int luaO_str2d (const char *s, size_t len, lua_Number *result) {
117 char *endptr; 117 char *endptr;
118 const char *e = s + len; /* string 's' ends here */
118 *result = lua_str2number(s, &endptr); 119 *result = lua_str2number(s, &endptr);
119 if (checkend(s, endptr)) return 1; /* conversion OK? */ 120 if (checkend(s, e, endptr)) return 1; /* conversion OK? */
120 *result = cast_num(strtoul(s, &endptr, 0)); /* try hexadecimal */ 121 *result = cast_num(strtoul(s, &endptr, 0)); /* try hexadecimal */
121 return checkend(s, endptr); 122 return checkend(s, e, endptr);
122} 123}
123 124
124 125
diff --git a/lobject.h b/lobject.h
index b9e554b4..823b5cd2 100644
--- a/lobject.h
+++ b/lobject.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lobject.h,v 2.42 2010/07/26 15:53:23 roberto Exp roberto $ 2** $Id: lobject.h,v 2.43 2010/11/26 14:32:31 roberto Exp roberto $
3** Type definitions for Lua objects 3** Type definitions for Lua objects
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -412,7 +412,7 @@ LUAI_FUNC int luaO_fb2int (int x);
412LUAI_FUNC int luaO_ceillog2 (lu_int32 x); 412LUAI_FUNC int luaO_ceillog2 (lu_int32 x);
413LUAI_FUNC lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2); 413LUAI_FUNC lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2);
414LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); 414LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2);
415LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); 415LUAI_FUNC int luaO_str2d (const char *s, size_t len, lua_Number *result);
416LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, 416LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,
417 va_list argp); 417 va_list argp);
418LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); 418LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
diff --git a/lvm.c b/lvm.c
index a20367ad..06dc4861 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.124 2010/10/25 19:01:37 roberto Exp roberto $ 2** $Id: lvm.c,v 2.125 2010/10/29 17:52:46 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -35,7 +35,7 @@
35const TValue *luaV_tonumber (const TValue *obj, TValue *n) { 35const TValue *luaV_tonumber (const TValue *obj, TValue *n) {
36 lua_Number num; 36 lua_Number num;
37 if (ttisnumber(obj)) return obj; 37 if (ttisnumber(obj)) return obj;
38 if (ttisstring(obj) && luaO_str2d(svalue(obj), &num)) { 38 if (ttisstring(obj) && luaO_str2d(svalue(obj), tsvalue(obj)->len, &num)) {
39 setnvalue(n, num); 39 setnvalue(n, num);
40 return n; 40 return n;
41 } 41 }