summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2006-05-24 11:16:39 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2006-05-24 11:16:39 -0300
commit20f4bbdc3a39446345e5f6433c7c71de60f8a0b7 (patch)
treec89f5df27adca6d82254833eb52a56d49c1ca14e
parentc408158047c24879887379d2f0cec71fd30604cb (diff)
downloadlua-20f4bbdc3a39446345e5f6433c7c71de60f8a0b7.tar.gz
lua-20f4bbdc3a39446345e5f6433c7c71de60f8a0b7.tar.bz2
lua-20f4bbdc3a39446345e5f6433c7c71de60f8a0b7.zip
does not accept garbage after options (e.g., -ixxx)
-rw-r--r--lua.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/lua.c b/lua.c
index a6405f6a..8cf83087 100644
--- a/lua.c
+++ b/lua.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lua.c,v 1.157 2005/12/29 16:23:32 roberto Exp roberto $ 2** $Id: lua.c,v 1.158 2006/04/10 18:27:23 roberto Exp roberto $
3** Lua stand-alone interpreter 3** Lua stand-alone interpreter
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -252,17 +252,30 @@ static int handle_script (lua_State *L, char **argv, int n) {
252} 252}
253 253
254 254
255/* check that argument has no extra characters at the end */
256#define notail(x) {if ((x)[2] != '\0') return -1;}
257
258
255static int collectargs (char **argv, int *pi, int *pv, int *pe) { 259static int collectargs (char **argv, int *pi, int *pv, int *pe) {
256 int i; 260 int i;
257 for (i = 1; argv[i] != NULL; i++) { 261 for (i = 1; argv[i] != NULL; i++) {
258 if (argv[i][0] != '-') /* not an option? */ 262 if (argv[i][0] != '-') /* not an option? */
259 return i; 263 return i;
260 switch (argv[i][1]) { /* option */ 264 switch (argv[i][1]) { /* option */
261 case '-': return (argv[i+1] != NULL ? i+1 : 0); 265 case '-':
262 case '\0': return i; 266 notail(argv[i]);
263 case 'i': *pi = 1; /* go through */ 267 return (argv[i+1] != NULL ? i+1 : 0);
264 case 'v': *pv = 1; break; 268 case '\0':
265 case 'e': *pe = 1; /* go through */ 269 return i;
270 case 'i':
271 notail(argv[i]);
272 *pi = 1; /* go through */
273 case 'v':
274 notail(argv[i]);
275 *pv = 1;
276 break;
277 case 'e':
278 *pe = 1; /* go through */
266 case 'l': 279 case 'l':
267 if (argv[i][2] == '\0') { 280 if (argv[i][2] == '\0') {
268 i++; 281 i++;