From owner-svn-src-all@freebsd.org Fri Apr 8 07:57:58 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E3870B08315; Fri, 8 Apr 2016 07:57:58 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from degoeje.nl (degoeje.nl [81.169.238.128]) by mx1.freebsd.org (Postfix) with ESMTP id A9F8C1FE2; Fri, 8 Apr 2016 07:57:57 +0000 (UTC) (envelope-from pieter@degoeje.nl) Received: from [192.168.1.250] (unknown [188.203.228.182]) by degoeje.nl (Postfix) with ESMTPSA id 80C2315C0686; Fri, 8 Apr 2016 09:51:03 +0200 (CEST) Subject: Re: svn commit: r297633 - in head: sys/cddl/contrib/opensolaris/uts/common/fs/zfs sys/fs/ext2fs sys/kern sys/sys sys/ufs/ffs sys/ufs/ufs sys/vm usr.bin/rctl To: Edward Tomasz Napierala , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org References: <201604070423.u374NP0Z021115@repo.freebsd.org> From: Pieter de Goeje Message-ID: <570762E4.6080706@degoeje.nl> Date: Fri, 8 Apr 2016 09:51:00 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <201604070423.u374NP0Z021115@repo.freebsd.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.0 required=3.5 tests=ALL_TRUSTED autolearn=ham autolearn_force=no version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on degoeje.nl X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Apr 2016 07:57:59 -0000 Op 2016-04-07 om 06:23 schreef Edward Tomasz Napierala: > +static uint64_t > +xmul(uint64_t a, uint64_t b) > +{ > + uint64_t c; > + > + if (a == 0 || b == 0) > + return (0); > + > + c = a * b; > + > + if (c < a || c < b) > + return (UINT64_MAX); If the intent is to check for overflow, then this check is insufficient. It fails for example if a = 2^32+1 and b = 2^32. This works for all cases, assuming a != 0: if(UINT64_MAX / a > b) return (UINT64_MAX); If the extra division is too expensive, GCC and clang provide __builtin_mul_overflow(). -- Pieter de Goeje