summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorOpportunityLiu <[email protected]>2019-07-02 11:32:13 +0800
committerOpportunityLiu <[email protected]>2019-07-02 11:32:13 +0800
commitaab06410fd763538632d82dee0d68a20f2d3e986 (patch)
treef2be6485248fb614dfa5f2890735548093a853d7 /core/src
parente2dc6e831a3c5114947040d11e5c0e6a9812e1ad (diff)
fix assert
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/io/file.h2
-rw-r--r--core/src/xmake/io/file_flush.c2
-rw-r--r--core/src/xmake/io/file_path.c2
-rw-r--r--core/src/xmake/io/file_read.c24
-rw-r--r--core/src/xmake/io/file_seek.c2
-rw-r--r--core/src/xmake/io/file_write.c7
6 files changed, 18 insertions, 21 deletions
diff --git a/core/src/xmake/io/file.h b/core/src/xmake/io/file.h
index 27a39264a..c177999c3 100644
--- a/core/src/xmake/io/file.h
+++ b/core/src/xmake/io/file.h
@@ -98,7 +98,7 @@ typedef struct __xm_io_file
do \
{ \
lua_pushnil(lua); \
- lua_pushliteral(lua, "error: file has been closed", reason); \
+ lua_pushliteral(lua, "error: file has been closed"); \
return 2; \
} while (0)
diff --git a/core/src/xmake/io/file_flush.c b/core/src/xmake/io/file_flush.c
index dceb00e56..9d296037b 100644
--- a/core/src/xmake/io/file_flush.c
+++ b/core/src/xmake/io/file_flush.c
@@ -60,11 +60,9 @@ tb_int_t xm_io_file_flush(lua_State* lua)
tb_assert_and_check_return_val(lua, 0);
xm_io_file* file = xm_io_getfile(lua);
-
if (xm_io_file_is_closed(file)) xm_io_file_error_closed(lua);
tb_bool_t succeed = xm_io_file_is_file(file) ? xm_io_file_flush(file) : xm_io_std_flush(file);
-
if (!succeed) xm_io_file_error(lua, file, "failed to flush file");
lua_pushboolean(lua, tb_true);
xm_io_file_success();
diff --git a/core/src/xmake/io/file_path.c b/core/src/xmake/io/file_path.c
index bda236077..8c84fbbc0 100644
--- a/core/src/xmake/io/file_path.c
+++ b/core/src/xmake/io/file_path.c
@@ -44,9 +44,7 @@ tb_int_t xm_io_file_path(lua_State* lua)
// get file pointer
xm_io_file* fp = xm_io_getfile(lua);
-
if (xm_io_file_is_closed(fp)) xm_io_file_error_closed(lua);
-
lua_pushstring(lua, fp->path);
// ok
return 1;
diff --git a/core/src/xmake/io/file_read.c b/core/src/xmake/io/file_read.c
index 533fe0758..885835305 100644
--- a/core/src/xmake/io/file_read.c
+++ b/core/src/xmake/io/file_read.c
@@ -224,10 +224,10 @@ static tb_int_t buffer_pushline(luaL_Buffer* buf, xm_io_file* file, tb_char_t co
tb_byte_t readbuf[512];
tb_size_t conlen = tb_strlen(continuation);
- tb_buffer_t readdata;
- tb_assert_and_check_return_val(tb_buffer_init(&readdata), 0);
- tb_buffer_t transdata;
- tb_assert_and_check_return_val(tb_buffer_init(&transdata), 0);
+ tb_buffer_t readdata, transdata;
+ tb_bool_t rok = tb_buffer_init(&readdata);
+ tb_bool_t tok = tb_buffer_init(&transdata);
+ tb_assert_and_check_return_val(rok && tok, 0);
// transcode is redundant, write to transdata directly
tb_bool_t notrans = charset == TB_CHARSET_TYPE_UTF8 || binary;
while (1)
@@ -425,7 +425,8 @@ static tb_int_t read_n(lua_State* lua, xm_io_file* file, tb_char_t const* contin
else
{
tb_buffer_t buf;
- tb_assert_and_check_return_val(tb_buffer_init(&buf), 0);
+ tb_bool_t ok = tb_buffer_init(&buf);
+ tb_assert_and_check_return_val(ok, 0);
tb_byte_t* bufptr = tb_buffer_resize(&buf, n + 1);
tb_assert(bufptr);
tb_long_t readsize = tb_file_read(file->file_ref, bufptr, n);
@@ -558,13 +559,13 @@ static tb_int_t std_read_n(lua_State* lua, xm_io_file* file, tb_char_t const* co
}
#ifdef TB_CONFIG_OS_WINDOWS
tb_buffer_t readbuf, transbuf;
- tb_assert_and_check_return_val(tb_buffer_init(&readbuf), 0);
+ tb_bool_t rok = tb_buffer_init(&readbuf);
+ tb_bool_t tok = tb_buffer_init(&transbuf);
+ tb_assert_and_check_return_val(rok && tok, 0);
tb_wchar_t* readbuf_ptr = (tb_wchar_t*)tb_buffer_resize(&readbuf, (tb_size_t)((n + 1) * sizeof(tb_wchar_t)));
tb_assert(readbuf_ptr);
-
- tb_size_t readcount = fread(readbuf_ptr, sizeof(tb_wchar_t), n, file->std_ref);
- readbuf_ptr[readcount] = L'\0'; // add null termination for tb_wcstombs
- tb_assert_and_check_return_val(tb_buffer_init(&transbuf), 0);
+ tb_size_t readcount = fread(readbuf_ptr, sizeof(tb_wchar_t), n, file->std_ref);
+ readbuf_ptr[readcount] = L'\0'; // add null termination for tb_wcstombs
tb_char_t* transbuf_ptr = (tb_char_t*)tb_buffer_resize(&transbuf, (tb_size_t)(n * 3));
tb_assert(transbuf_ptr);
@@ -574,7 +575,8 @@ static tb_int_t std_read_n(lua_State* lua, xm_io_file* file, tb_char_t const* co
tb_buffer_exit(&transbuf);
#else
tb_buffer_t buf;
- tb_assert_and_check_return_val(tb_buffer_init(&buf), 0);
+ tb_bool_t ok = tb_buffer_init(&buf);
+ tb_assert_and_check_return_val(ok, 0);
tb_char_t* buf_ptr = (tb_char_t*)tb_buffer_resize(&buf, (tb_size_t)n);
tb_assert(buf_ptr);
diff --git a/core/src/xmake/io/file_seek.c b/core/src/xmake/io/file_seek.c
index 21d5b9c0f..5dd963138 100644
--- a/core/src/xmake/io/file_seek.c
+++ b/core/src/xmake/io/file_seek.c
@@ -46,9 +46,7 @@ tb_int_t xm_io_file_seek(lua_State* lua)
xm_io_file* file = xm_io_getfile(lua);
tb_char_t const* whence = luaL_optstring(lua, 2, "cur");
tb_hong_t offset = (tb_hong_t)luaL_optnumber(lua, 3, 0);
-
tb_assert_and_check_return_val(file && whence, 0);
-
if (xm_io_file_is_file(file))
{
if (xm_io_file_is_closed_file(file)) xm_io_file_error_closed(lua);
diff --git a/core/src/xmake/io/file_write.c b/core/src/xmake/io/file_write.c
index 2c1e49453..0a055324f 100644
--- a/core/src/xmake/io/file_write.c
+++ b/core/src/xmake/io/file_write.c
@@ -52,8 +52,8 @@ static tb_void_t transcode_write(xm_io_file* file, tb_char_t const* data, tb_siz
tb_assert(file && data && xm_io_file_is_file(file) && !xm_io_file_is_closed(file));
tb_buffer_t buf;
- tb_assert_and_check_return(tb_buffer_init(&buf));
-
+ tb_bool_t ok = tb_buffer_init(&buf);
+ tb_assert_and_check_return(ok);
tb_byte_t* buf_ptr = tb_buffer_resize(&buf, (size + 1) * 2);
tb_assert(buf_ptr);
tb_long_t buf_size = tb_charset_conv_cstr(TB_CHARSET_TYPE_UTF8, file->encoding, data, buf_ptr, size * 2);
@@ -84,7 +84,8 @@ static tb_void_t std_write(xm_io_file* file, tb_char_t const* data, tb_size_t si
// write to the stdout
DWORD real = 0;
tb_buffer_t wbuf;
- tb_assert_and_check_return(tb_buffer_init(&wbuf));
+ tb_bool_t ok = tb_buffer_init(&wbuf);
+ tb_assert_and_check_return(ok);
if (xm_io_file_is_tty(file))
{
// write to console