Skip to content

Commit 20b2551

Browse files
author
bjcscat
authored
Fix error handling for scandir call
1 parent 58e9cf2 commit 20b2551

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

fs/src/fs.cpp

Lines changed: 6 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,12 @@ int listdir(lua_State* L)
418419

419420
lua_settable(L, -3);
420421
}
421-
422+
422423
delete req;
423424

425+
if (err != UV_EOF)
426+
luaL_errorL(L, "%s", uv_strerror(err));
427+
424428
return 1;
425429
}
426430
);

0 commit comments

Comments
 (0)