summaryrefslogtreecommitdiff
path: root/core/src/xmake/libc/strndup.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/xmake/libc/strndup.c')
-rw-r--r--core/src/xmake/libc/strndup.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/core/src/xmake/libc/strndup.c b/core/src/xmake/libc/strndup.c
index f61cebb2c..138a4907f 100644
--- a/core/src/xmake/libc/strndup.c
+++ b/core/src/xmake/libc/strndup.c
@@ -38,16 +38,18 @@ tb_int_t xm_libc_strndup(lua_State *lua) {
// do strndup
tb_char_t const *s = tb_null;
- if (lua_isnumber(lua, 1))
+ if (lua_isnumber(lua, 1)) {
s = (tb_char_t const *)(tb_size_t)lua_tointeger(lua, 1);
- else if (lua_isstring(lua, 2))
+ } else if (lua_isstring(lua, 2)) {
s = lua_tostring(lua, 2);
- else
+ } else {
xm_libc_return_error(lua, "libc.strndup(invalid args)!");
+ }
tb_int_t n = (tb_int_t)lua_tointeger(lua, 2);
- if (s && n >= 0)
+ if (s && n >= 0) {
lua_pushlstring(lua, s, n);
- else
+ } else {
lua_pushliteral(lua, "");
+ }
return 1;
}