Skip to content

Commit 721ba96

Browse files
committed
Review requests: omit unnecessary ngroups > 0 and leave early with ngroup < 1
1 parent f84a9a6 commit 721ba96

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/misc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ static int luv_getgroups(lua_State* L) {
533533
if (ngroups > 0) {
534534
groups = (gid_t*)malloc(ngroups * sizeof(gid_t));
535535
}
536-
if (ngroups > 0 && !groups) {
536+
if (!groups) {
537537
return luaL_error(L, "Error allocating memory for groups");
538538
}
539539

@@ -560,6 +560,10 @@ static int luv_setgroups(lua_State* L) {
560560
luaL_checktype(L, 1, LUA_TTABLE);
561561
ngroups = lua_rawlen(L, 1);
562562

563+
if (ngroups < 1) {
564+
return 0;
565+
}
566+
563567
groups = (gid_t*)malloc(ngroups * sizeof(gid_t));
564568
if (!groups && ngroups > 0) {
565569
return luaL_error(L, "Error allocating memory for groups");

0 commit comments

Comments
 (0)