svn commit: r201999 - head/lib/libc/stdio

Andrey Chernov ache at nagual.pp.ru
Sun Jan 10 21:25:51 UTC 2010


On Sun, Jan 10, 2010 at 02:30:30PM +0000, Colin Percival wrote:
> +	 * Check for integer overflow.  As an optimization, first check that
> +	 * at least one of {count, size} is at least 2^16, since if both
> +	 * values are less than that, their product can't possible overflow
> +	 * (size_t is always at least 32 bits on FreeBSD).
> +	 */
> +	if (((count | size) > 0xFFFF) &&
> +	    (count > SIZE_MAX / size)) {
> +		errno = EINVAL;
> +		fp->_flags |= __SERR;
> +		return (0);
> +	}

1) I don't think that this is good place of exact constants like 0xFFFF, 
usually we don't use such things in overflow checks (see all other ones).
fread/fwrite are already slow as designed, so optimizing one time argument 
check looks strange.

2) fp->_flags |= __SERR;
This flag is for errors in the file stream, not for errors in 
the arguments. Please back that line out.

3) errno should be EOVERFLOW, see other owerflow checks in the stdio.

-- 
http://ache.pp.ru/


More information about the svn-src-head mailing list