diff options
author | Mike Pall <mike> | 2025-03-09 16:21:29 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2025-03-09 16:21:29 +0100 |
commit | d508715ab657261e8437a52c1b1966c20ab1631d (patch) | |
tree | ed5e601a15fb5919abc832ef36192b72071f3cd0 | |
parent | 62e362afbb1d100c892d2782c5862ad18bc464f2 (diff) | |
download | luajit-d508715ab657261e8437a52c1b1966c20ab1631d.tar.gz luajit-d508715ab657261e8437a52c1b1966c20ab1631d.tar.bz2 luajit-d508715ab657261e8437a52c1b1966c20ab1631d.zip |
Add compatibility string coercion for fp:seek() argument.
Reported by Magnus Wibeck. #1343
-rw-r--r-- | src/Makefile.dep | 2 | ||||
-rw-r--r-- | src/lib_io.c | 4 |
2 files changed, 4 insertions, 2 deletions
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 \ | |||
18 | lib_init.o: lib_init.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h | 18 | lib_init.o: lib_init.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h |
19 | lib_io.o: lib_io.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ | 19 | lib_io.o: lib_io.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \ |
20 | lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_ff.h \ | 20 | lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_state.h lj_ff.h \ |
21 | lj_ffdef.h lj_lib.h lj_libdef.h | 21 | lj_ffdef.h lj_lib.h lj_strscan.h lj_libdef.h |
22 | lib_jit.o: lib_jit.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h \ | 22 | lib_jit.o: lib_jit.c lua.h luaconf.h lauxlib.h lualib.h lj_arch.h \ |
23 | lj_obj.h lj_def.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h \ | 23 | lj_obj.h lj_def.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h \ |
24 | lj_bc.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_target.h \ | 24 | 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 @@ | |||
23 | #include "lj_state.h" | 23 | #include "lj_state.h" |
24 | #include "lj_ff.h" | 24 | #include "lj_ff.h" |
25 | #include "lj_lib.h" | 25 | #include "lj_lib.h" |
26 | #include "lj_strscan.h" | ||
26 | 27 | ||
27 | /* Userdata payload for I/O file. */ | 28 | /* Userdata payload for I/O file. */ |
28 | typedef struct IOFileUD { | 29 | typedef struct IOFileUD { |
@@ -324,13 +325,14 @@ LJLIB_CF(io_method_seek) | |||
324 | FILE *fp = io_tofile(L)->fp; | 325 | FILE *fp = io_tofile(L)->fp; |
325 | int opt = lj_lib_checkopt(L, 2, 1, "\3set\3cur\3end"); | 326 | int opt = lj_lib_checkopt(L, 2, 1, "\3set\3cur\3end"); |
326 | int64_t ofs = 0; | 327 | int64_t ofs = 0; |
327 | cTValue *o; | 328 | TValue *o; |
328 | int res; | 329 | int res; |
329 | if (opt == 0) opt = SEEK_SET; | 330 | if (opt == 0) opt = SEEK_SET; |
330 | else if (opt == 1) opt = SEEK_CUR; | 331 | else if (opt == 1) opt = SEEK_CUR; |
331 | else if (opt == 2) opt = SEEK_END; | 332 | else if (opt == 2) opt = SEEK_END; |
332 | o = L->base+2; | 333 | o = L->base+2; |
333 | if (o < L->top) { | 334 | if (o < L->top) { |
335 | if (tvisstr(o)) lj_strscan_num(strV(o), o); | ||
334 | if (tvisint(o)) | 336 | if (tvisint(o)) |
335 | ofs = (int64_t)intV(o); | 337 | ofs = (int64_t)intV(o); |
336 | else if (tvisnum(o)) | 338 | else if (tvisnum(o)) |