• R/O
  • SSH

aotus: Commit

Repository for the aotus library is now located at https://github.com/apes-suite/aotus


Commit MetaInfo

Revision85dac29555247e50773ba41723730fa3eea2d647 (tree)
Zeit2022-05-02 18:28:20
AutorHarald Klimach <harald.klimach@dlr....>
CommiterHarald Klimach

Log Message

Applied patch 1 for Lua 5.4.4

lua.c assumes that argv has at least one element.

Ändern Zusammenfassung

Diff

diff -r de2bd538f02d -r 85dac2955524 external/lua-5.4.4/src/lua.c
--- a/external/lua-5.4.4/src/lua.c Sat Mar 05 01:27:56 2022 +0100
+++ b/external/lua-5.4.4/src/lua.c Mon May 02 11:28:20 2022 +0200
@@ -177,10 +177,11 @@
177177 ** to the script (everything after 'script') go to positive indices;
178178 ** other arguments (before the script name) go to negative indices.
179179 ** If there is no script name, assume interpreter's name as base.
180+** (If there is no interpreter's name either, 'script' is -1, so
181+** table sizes are zero.)
180182 */
181183 static void createargtable (lua_State *L, char **argv, int argc, int script) {
182184 int i, narg;
183- if (script == argc) script = 0; /* no script name? */
184185 narg = argc - (script + 1); /* number of positive indices */
185186 lua_createtable(L, narg, script + 1);
186187 for (i = 0; i < argc; i++) {
@@ -268,14 +269,23 @@
268269
269270 /*
270271 ** Traverses all arguments from 'argv', returning a mask with those
271-** needed before running any Lua code (or an error code if it finds
272-** any invalid argument). 'first' returns the first not-handled argument
273-** (either the script name or a bad argument in case of error).
272+** needed before running any Lua code or an error code if it finds any
273+** invalid argument. In case of error, 'first' is the index of the bad
274+** argument. Otherwise, 'first' is -1 if there is no program name,
275+** 0 if there is no script name, or the index of the script name.
274276 */
275277 static int collectargs (char **argv, int *first) {
276278 int args = 0;
277279 int i;
278- for (i = 1; argv[i] != NULL; i++) {
280+ if (argv[0] != NULL) { /* is there a program name? */
281+ if (argv[0][0]) /* not empty? */
282+ progname = argv[0]; /* save it */
283+ }
284+ else { /* no program name */
285+ *first = -1;
286+ return 0;
287+ }
288+ for (i = 1; argv[i] != NULL; i++) { /* handle arguments */
279289 *first = i;
280290 if (argv[i][0] != '-') /* not an option? */
281291 return args; /* stop handling options */
@@ -316,7 +326,7 @@
316326 return has_error;
317327 }
318328 }
319- *first = i; /* no script name */
329+ *first = 0; /* no script name */
320330 return args;
321331 }
322332
@@ -609,8 +619,8 @@
609619 char **argv = (char **)lua_touserdata(L, 2);
610620 int script;
611621 int args = collectargs(argv, &script);
622+ int optlim = (script > 0) ? script : argc; /* first argv not an option */
612623 luaL_checkversion(L); /* check that interpreter has correct version */
613- if (argv[0] && argv[0][0]) progname = argv[0];
614624 if (args == has_error) { /* bad arg? */
615625 print_usage(argv[script]); /* 'script' has index of bad arg. */
616626 return 0;
@@ -628,14 +638,15 @@
628638 if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */
629639 return 0; /* error running LUA_INIT */
630640 }
631- if (!runargs(L, argv, script)) /* execute arguments -e and -l */
641+ if (!runargs(L, argv, optlim)) /* execute arguments -e and -l */
632642 return 0; /* something failed */
633- if (script < argc && /* execute main script (if there is one) */
634- handle_script(L, argv + script) != LUA_OK)
635- return 0;
643+ if (script > 0) { /* execute main script (if there is one) */
644+ if (handle_script(L, argv + script) != LUA_OK)
645+ return 0; /* interrupt in case of error */
646+ }
636647 if (args & has_i) /* -i option? */
637648 doREPL(L); /* do read-eval-print loop */
638- else if (script == argc && !(args & (has_e | has_v))) { /* no arguments? */
649+ else if (script < 1 && !(args & (has_e | has_v))) { /* no active option? */
639650 if (lua_stdin_is_tty()) { /* running in interactive mode? */
640651 print_version();
641652 doREPL(L); /* do read-eval-print loop */
Show on old repository browser