From 48f852eefe1f781756e86a2b3fb2bab5e16deda9 Mon Sep 17 00:00:00 2001 From: ruki Date: Fri, 5 Jul 2019 23:58:35 +0800 Subject: fix read num and line/free --- core/src/xmake/io/file_read.c | 12 +++--------- core/src/xmake/sandbox/interactive.c | 3 ++- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c index 6581bff9d..5ae7b91b3 100644 --- a/core/src/xmake/io/file_read.c +++ b/core/src/xmake/io/file_read.c @@ -453,15 +453,9 @@ static tb_int_t xm_io_file_std_read_num(lua_State* lua, xm_io_file* file, tb_cha // read number tb_char_t strbuf[512]; if (tb_stdfile_gets(file->std_ref, strbuf, tb_arrayn(strbuf))) - { - lua_pushnumber(lua, tb_s10tod(strbuf)); - return 1; - } - else - { - lua_pushnil(lua); - return 0; - } + lua_pushnumber(lua, tb_s10tod(strbuf)); // TODO check invalid float number string and push nil + else lua_pushnil(lua); + return 1; } /* diff --git a/core/src/xmake/sandbox/interactive.c b/core/src/xmake/sandbox/interactive.c index 75f36d947..95d01a19c 100644 --- a/core/src/xmake/sandbox/interactive.c +++ b/core/src/xmake/sandbox/interactive.c @@ -40,6 +40,7 @@ #ifdef XM_CONFIG_API_HAVE_READLINE # include # include +# include # include // on some OS (like centos) required #endif @@ -160,7 +161,7 @@ static tb_size_t xm_sandbox_readline(tb_char_t* data, tb_size_t maxn, tb_char_t tb_size_t size = tb_strlcpy(data, line, maxn); // free line - tb_free(line); + free((void*)line); // truncated? if (size >= maxn) return 0; -- cgit v1.3.1