Correctly set the return length regardless of the relative size of the

user's buffer.  Simplify the logic a bit.  (Can we have a version of
min() for size_t?)
This commit is contained in:
Garrett Wollman 1998-08-31 15:34:55 +00:00
parent cdb5ef5fba
commit d224dbc106
1 changed files with 3 additions and 6 deletions

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94
* $Id: uipc_socket.c,v 1.42 1998/07/18 18:48:45 fenner Exp $ * $Id: uipc_socket.c,v 1.43 1998/08/23 03:06:59 wollman Exp $
*/ */
#include <sys/param.h> #include <sys/param.h>
@ -1083,11 +1083,8 @@ sooptcopyout(sopt, buf, len)
* interface is not idempotent; the entire answer must * interface is not idempotent; the entire answer must
* generated ahead of time. * generated ahead of time.
*/ */
valsize = len; valsize = min(len, sopt->sopt_valsize);
if (sopt->sopt_valsize < valsize) { sopt->sopt_valsize = len;
valsize = sopt->sopt_valsize;
sopt->sopt_valsize = len;
}
if (sopt->sopt_val != 0) { if (sopt->sopt_val != 0) {
if (sopt->sopt_p != 0) if (sopt->sopt_p != 0)
error = copyout(buf, sopt->sopt_val, valsize); error = copyout(buf, sopt->sopt_val, valsize);