<HTML><BODY><div class="cl-tgfxh8wt76"><div>Hi, Sergey! Thanks for the patch!</div><div> </div><div>LGTM.<br><br> </div><div data-signature-widget="container"><div data-signature-widget="content"><div>--<br>Best regards,</div><div>Evgeniy Temirgaleev</div></div></div><br><div class="mail-quote-collapse"><blockquote style="border-left:1px solid #0857A6;margin:10px;padding:0 0 0 10px"><span>From: Sergey Kaplun <<a href="mailto:skaplun@tarantool.org">skaplun@tarantool.org</a>><br>To: Sergey Bronnikov <<a href="mailto:sergeyb@tarantool.org">sergeyb@tarantool.org</a>>, Evgeniy Temirgaleev <<a href="mailto:e.temirgaleev@tarantool.org">e.temirgaleev@tarantool.org</a>><br>Cc: tarantool-patches@dev.tarantool.org, Sergey Kaplun <<a href="mailto:skaplun@tarantool.org">skaplun@tarantool.org</a>><br>Date: Tuesday, July 21, 2026 10:59 AM +03:00</span><br> <div><div id=""><div class="cl-afbp086mt7"><div class="js-helper_mr_css_attr js-readmsg-msg_mr_css_attr"><div id="style_17846207950940343049_mr_css_attr"><div id="style_17846207950940343049_BODY_mr_css_attr">From: Mike Pall <mike><br><br>Reported by Magnus Wibeck.<br><br>(cherry picked from commit d508715ab657261e8437a52c1b1966c20ab1631d)<br><br>In LuaJIT the second `fp:seek()` argument (offset) doesn't coerce from a<br>string to an integer value, unlike PUC-Rio Lua 5.1 does.<br><br>This patch adds missing coercion.<br><br>Sergey Kaplun:<br>* added the description and the test for the problem<br><br>Part of tarantool/tarantool#12880<br>---<br><br>Branch: <a href="https://github.com/tarantool/luajit/tree/skaplun/lj-1343-fseek-offset-coercion">https://github.com/tarantool/luajit/tree/skaplun/lj-1343-fseek-offset-coercion</a><br>Related issues:<br>* <a href="https://github.com/LuaJIT/LuaJIT/issues/1343">https://github.com/LuaJIT/LuaJIT/issues/1343</a><br>* <a href="https://github.com/tarantool/tarantool/issues/12880">https://github.com/tarantool/tarantool/issues/12880</a><br><br>src/Makefile.dep.original | 2 +-<br>src/lib_io.c | 4 +++-<br>.../lj-1343-fseek-offset-coercion.test.lua | 23 +++++++++++++++++++<br>3 files changed, 27 insertions(+), 2 deletions(-)<br>create mode 100644 test/tarantool-tests/lj-1343-fseek-offset-coercion.test.lua<br><br>diff --git a/src/Makefile.dep.original b/src/Makefile.dep.original<br>index 436685f5..acc6b3ba 100644<br>--- a/src/Makefile.dep.original<br>+++ b/src/Makefile.dep.original<br>@@ -21,7 +21,7 @@ lib_ffi.o: lib_ffi.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \<br>lib_init.o: lib_init.c lua.h luaconf.h lauxlib.h lualib.h lmisclib.h lj_arch.h<br>lib_io.o: lib_io.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \<br>lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_buf.h lj_str.h lj_state.h \<br>- lj_strfmt.h lj_ff.h lj_ffdef.h lj_lib.h lj_libdef.h<br>+ lj_strfmt.h lj_ff.h lj_ffdef.h lj_lib.h lj_strscan.h lj_libdef.h<br>lib_jit.o: lib_jit.c lua.h luaconf.h lauxlib.h lualib.h lj_obj.h lj_def.h \<br>lj_arch.h lj_gc.h lj_err.h lj_errmsg.h lj_debug.h lj_str.h lj_tab.h \<br>lj_state.h lj_bc.h lj_ctype.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h \<br>diff --git a/src/lib_io.c b/src/lib_io.c<br>index ef39e535..2d0abf78 100644<br>--- a/src/lib_io.c<br>+++ b/src/lib_io.c<br>@@ -25,6 +25,7 @@<br>#include "lj_strfmt.h"<br>#include "lj_ff.h"<br>#include "lj_lib.h"<br>+#include "lj_strscan.h"<br><br>/* Userdata payload for I/O file. */<br>typedef struct IOFileUD {<br>@@ -317,13 +318,14 @@ LJLIB_CF(io_method_seek)<br>FILE *fp = io_tofile(L)->fp;<br>int opt = lj_lib_checkopt(L, 2, 1, "\3set\3cur\3end");<br>int64_t ofs = 0;<br>- cTValue *o;<br>+ TValue *o;<br>int res;<br>if (opt == 0) opt = SEEK_SET;<br>else if (opt == 1) opt = SEEK_CUR;<br>else if (opt == 2) opt = SEEK_END;<br>o = L->base+2;<br>if (o < L->top) {<br>+ if (tvisstr(o)) lj_strscan_num(strV(o), o);<br>if (tvisint(o))<br>ofs = (int64_t)intV(o);<br>else if (tvisnum(o))<br>diff --git a/test/tarantool-tests/lj-1343-fseek-offset-coercion.test.lua b/test/tarantool-tests/lj-1343-fseek-offset-coercion.test.lua<br>new file mode 100644<br>index 00000000..fdfc6ce5<br>--- /dev/null<br>+++ b/test/tarantool-tests/lj-1343-fseek-offset-coercion.test.lua<br>@@ -0,0 +1,23 @@<br>+local tap = require('tap')<br>+<br>+-- The test file to demonstrate LuaJIT's missing coercion for the<br>+-- `io.fseek()` offset argument.<br>+-- See also: <a href="https://github.com/LuaJIT/LuaJIT/issues/1343">https://github.com/LuaJIT/LuaJIT/issues/1343</a>.<br>+<br>+local test = tap.test('lj-1343-fseek-offset-coercion')<br>+<br>+test:plan(2)<br>+<br>+local f = io.tmpfile()<br>+<br>+f:write('12345')<br>+<br>+f:seek('set', 0)<br>+f:seek('set', '1')<br>+test:is(f:read('*all'), '2345', 'base coercion test')<br>+<br>+f:seek('set', 0)<br>+f:seek('set', '1.9')<br>+test:is(f:read('*all'), '2345', 'coercion test for non-integer value')<br>+<br>+test:done(true)<br>--<br>2.55.0</div></div></div></div></div></div></blockquote></div></div></BODY></HTML>