From a582f1a26210605d3bbb685f6f62fd7648f17a88 Mon Sep 17 00:00:00 2001 From: Magnus Wibeck Date: Thu, 13 Feb 2025 17:08:30 +0100 Subject: [PATCH] Use standard number coercion for file:seek. #1343 Code by @Buristan. --- src/lib_io.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/lib_io.c b/src/lib_io.c index 4e0397d4..3be71d04 100644 --- a/src/lib_io.c +++ b/src/lib_io.c @@ -329,14 +329,8 @@ LJLIB_CF(io_method_seek) else if (opt == 1) opt = SEEK_CUR; else if (opt == 2) opt = SEEK_END; o = L->base+2; - if (o < L->top) { - if (tvisint(o)) - ofs = (int64_t)intV(o); - else if (tvisnum(o)) - ofs = (int64_t)numV(o); - else if (!tvisnil(o)) - lj_err_argt(L, 3, LUA_TNUMBER); - } + if (o < L->top && !tvisnil(o)) + ofs = (int64_t)lj_lib_checknum(L, 3); #if LJ_TARGET_POSIX res = fseeko(fp, ofs, opt); #elif _MSC_VER >= 1400