From 8622dc18bfa9da14136763e9538222fdec31a79a Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 27 Jan 1998 17:11:36 -0200 Subject: [PATCH] bug: format size limits with little problems --- bugs | 6 ++++++ lstrlib.c | 8 ++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bugs b/bugs index b9c05ca1..d2155964 100644 --- a/bugs +++ b/bugs @@ -18,3 +18,9 @@ Thu Jan 15 14:34:58 EDT 1998 ** llex.c Mon Jan 19 18:17:18 EDT 1998 >> wrong line number (+1) in error report when file starts with "#..." + +** lstrlib.c +Tue Jan 27 15:27:49 EDT 1998 +>> formats like "%020d" were considered too big (3 algarithms); moreover, +>> some sistems limit printf to at most 500 chars, so we can limit sizes +>> to 2 digits (99). diff --git a/lstrlib.c b/lstrlib.c index 8c963b11..a1b061ed 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.6 1998/01/09 14:44:55 roberto Exp $ +** $Id: lstrlib.c,v 1.7 1998/01/09 14:57:43 roberto Exp roberto $ ** Standard library for strings and pattern-matching ** See Copyright Notice in lua.h */ @@ -449,14 +449,14 @@ static void str_format (void) char *initf = strfrmt; form[0] = '%'; cap.level = 0; - strfrmt = match(strfrmt, "%d?%$?[-+ #]*(%d*)%.?(%d*)", &cap); - if (cap.capture[0].len > 3 || cap.capture[1].len > 3) /* < 1000? */ - lua_error("invalid format (width or precision too long)"); if (isdigit((unsigned char)initf[0]) && initf[1] == '$') { arg = initf[0] - '0'; initf += 2; /* skip the 'n$' */ } arg++; + strfrmt = match(initf, "[-+ #0]*(%d*)%.?(%d*)", &cap); + if (cap.capture[0].len > 2 || cap.capture[1].len > 2) /* < 100? */ + lua_error("invalid format (width or precision too long)"); strncpy(form+1, initf, strfrmt-initf+1); /* +1 to include convertion */ form[strfrmt-initf+2] = 0; buff = luaL_openspace(1000); /* to store the formatted value */