Skip to content

Commit b589795

Browse files
committed
unistd::getgrouplist: Simplify buffer resizing
1 parent 56c0167 commit b589795

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/unistd.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,8 @@ pub fn getgrouplist(user: &CString, group: Gid) -> Result<Vec<Gid>> {
10551055
return Err(Error::invalid_argument())
10561056
}
10571057

1058-
// Trigger buffer resizing
1059-
unsafe { groups.set_len(cap) };
1060-
groups.reserve(ngroups as usize - cap);
1058+
// Reserve space for at least ngroups
1059+
groups.reserve(ngroups as usize);
10611060

10621061
// Even if the buffer gets resized to bigger than ngroups_max,
10631062
// don't ever ask for more than ngroups_max groups

0 commit comments

Comments
 (0)