Skip to content

Commit 73306f1

Browse files
committed
fix #2
1 parent caf36eb commit 73306f1

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/lfs.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ utf8_filename(lua_State *L, const wchar_t * winfilename, int wsz, char *utf8buff
4040
sz = WideCharToMultiByte(CP_UTF8, 0, winfilename, wsz, utf8buffer, sz, NULL, NULL);
4141
if (sz == 0)
4242
return luaL_error(L, "convert to utf-8 filename fail");
43-
// not include end \0
44-
return sz - 1;
43+
if (wsz < 0) // not include end \0
44+
return sz - 1;
45+
return sz;
4546
}
4647

4748
#define DIR_METATABLE "SOLUNA_DIR"
@@ -56,7 +57,9 @@ windows_filename(lua_State *L, const char * utf8filename, int usz, wchar_t * win
5657
wsz = MultiByteToWideChar(CP_UTF8, 0, utf8filename, usz, winbuffer, wsz);
5758
if (wsz == 0)
5859
return luaL_error(L, "convert to windows utf-16 filename fail");
59-
return wsz - 1;
60+
if (usz < 0)
61+
return wsz - 1;
62+
return wsz;
6063
}
6164

6265
static void

0 commit comments

Comments
 (0)