Skip to content

Commit 9c79ce5

Browse files
author
bjcscat
authored
Fix error handling for scandir call (luau-lang#103)
1 parent 8c61171 commit 9c79ce5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/src/fs.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ int listdir(lua_State* L)
404404

405405
uv_dirent_t dir;
406406
int i = 0;
407-
while (uv_fs_scandir_next(req, &dir) != UV_EOF)
407+
int err = 0;
408+
while ((err = uv_fs_scandir_next(req, &dir)) >= 0)
408409
{
409410
lua_pushinteger(L, ++i);
410411

@@ -418,9 +419,11 @@ int listdir(lua_State* L)
418419

419420
lua_settable(L, -3);
420421
}
421-
422422
delete req;
423423

424+
if (err != UV_EOF)
425+
luaL_errorL(L, "%s", uv_strerror(err));
426+
424427
return 1;
425428
}
426429
);

0 commit comments

Comments
 (0)