fd: unify fd range check across the routines
While here annotate out of range as unlikely. Sponsored by: The FreeBSD Foundation
This commit is contained in:
parent
159dcc30a5
commit
d47f3fdb0a
@ -2637,7 +2637,7 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights_t *needrightsp,
|
||||
#endif
|
||||
|
||||
fdt = fdp->fd_files;
|
||||
if ((u_int)fd >= fdt->fdt_nfiles)
|
||||
if (__predict_false((u_int)fd >= fdt->fdt_nfiles))
|
||||
return (EBADF);
|
||||
/*
|
||||
* Fetch the descriptor locklessly. We avoid fdrop() races by
|
||||
|
@ -208,7 +208,7 @@ fget_locked(struct filedesc *fdp, int fd)
|
||||
|
||||
FILEDESC_LOCK_ASSERT(fdp);
|
||||
|
||||
if (fd < 0 || fd > fdp->fd_lastfile)
|
||||
if (__predict_false((u_int)fd >= fdp->fd_nfiles))
|
||||
return (NULL);
|
||||
|
||||
return (fdp->fd_ofiles[fd].fde_file);
|
||||
@ -221,11 +221,11 @@ fdeget_locked(struct filedesc *fdp, int fd)
|
||||
|
||||
FILEDESC_LOCK_ASSERT(fdp);
|
||||
|
||||
if (fd < 0 || fd > fdp->fd_lastfile)
|
||||
if (__predict_false((u_int)fd >= fdp->fd_nfiles))
|
||||
return (NULL);
|
||||
|
||||
fde = &fdp->fd_ofiles[fd];
|
||||
if (fde->fde_file == NULL)
|
||||
if (__predict_false(fde->fde_file == NULL))
|
||||
return (NULL);
|
||||
|
||||
return (fde);
|
||||
|
Loading…
Reference in New Issue
Block a user