From d508715ab657261e8437a52c1b1966c20ab1631d Mon Sep 17 00:00:00 2001 From: Mike Pall Date: Sun, 9 Mar 2025 16:21:29 +0100 Subject: Add compatibility string coercion for fp:seek() argument. Reported by Magnus Wibeck. #1343 --- src/Makefile.dep | 2 +- src/lib_io.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Makefile.dep b/src/Makefile.dep index 9e14d617..5b87d7c4 100644 --- a/src/Makefile.dep +++ b/src/Makefile.dep @@ -18,7 +18,7 @@ lib_ffi.o: lib_ffi.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ lib_init.o: lib_init.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h lib_io.o: lib_io.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_ff.h \ - lj_ffdef.h lj_lib.h lj_libdef.h + lj_ffdef.h lj_lib.h lj_strscan.h lj_libdef.h lib_jit.o: lib_jit.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h \ lj_obj.h lj_def.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h \ lj_bc.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_target.h \ diff --git a/src/lib_io.c b/src/lib_io.c index 6e330a73..cb6df46d 100644 --- a/src/lib_io.c +++ b/src/lib_io.c @@ -23,6 +23,7 @@ #include "lj_state.h" #include "lj_ff.h" #include "lj_lib.h" +#include "lj_strscan.h" /* Userdata payload for I/O file. */ typedef struct IOFileUD { @@ -324,13 +325,14 @@ LJLIB_CF(io_method_seek) FILE *fp = io_tofile(L)->fp; int opt = lj_lib_checkopt(L, 2, 1, "\3set\3cur\3end"); int64_t ofs = 0; - cTValue *o; + TValue *o; int res; if (opt == 0) opt = SEEK_SET; else if (opt == 1) opt = SEEK_CUR; else if (opt == 2) opt = SEEK_END; o = L->base+2; if (o < L->top) { + if (tvisstr(o)) lj_strscan_num(strV(o), o); if (tvisint(o)) ofs = (int64_t)intV(o); else if (tvisnum(o)) -- cgit v1.2.3-55-g6feb