aboutsummaryrefslogtreecommitdiff
path: root/lobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'lobject.c')
-rw-r--r--lobject.c13
1 files changed, 7 insertions, 6 deletions
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