From ccc4fc9cf001c19eac5be4453b76a6c438b5b1d4 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 6 Dec 2010 19:08:36 -0200 Subject: detection of erroneous numeric strings with \0 (such as "1\0") --- llex.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'llex.c') diff --git a/llex.c b/llex.c index 22a83ff1..5a742cf6 100644 --- a/llex.c +++ b/llex.c @@ -1,5 +1,5 @@ /* -** $Id: llex.c,v 2.40 2010/10/25 12:24:36 roberto Exp roberto $ +** $Id: llex.c,v 2.41 2010/11/18 18:38:44 roberto Exp roberto $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ @@ -200,6 +200,9 @@ static void buffreplace (LexState *ls, char from, char to) { #define getlocaledecpoint() (localeconv()->decimal_point[0]) #endif + +#define buff2d(b,e) luaO_str2d(luaZ_buffer(b), luaZ_bufflen(b) - 1, e) + /* ** in case of format error, try to change decimal point separator to ** the one defined in the current locale and check again @@ -208,7 +211,7 @@ static void trydecpoint (LexState *ls, SemInfo *seminfo) { char old = ls->decpoint; ls->decpoint = getlocaledecpoint(); buffreplace(ls, old, ls->decpoint); /* try new decimal separator */ - if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) { + if (!buff2d(ls->buff, &seminfo->r)) { /* format error with correct decimal point: no more options */ buffreplace(ls, ls->decpoint, '.'); /* undo change (for error message) */ lexerror(ls, "malformed number", TK_NUMBER); @@ -226,7 +229,7 @@ static void read_numeral (LexState *ls, SemInfo *seminfo) { } while (lislalnum(ls->current) || ls->current == '.'); save(ls, '\0'); buffreplace(ls, '.', ls->decpoint); /* follow locale for decimal point */ - if (!luaO_str2d(luaZ_buffer(ls->buff), &seminfo->r)) /* format error? */ + if (!buff2d(ls->buff, &seminfo->r)) /* format error? */ trydecpoint(ls, seminfo); /* try to update decimal point separator */ } -- cgit v1.2.3-55-g6feb