From owner-svn-src-all@freebsd.org Sat May 21 03:05:47 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 95B26B442C9; Sat, 21 May 2016 03:05:47 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-oi0-f50.google.com (mail-oi0-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 624E91E1C; Sat, 21 May 2016 03:05:47 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-oi0-f50.google.com with SMTP id b65so62349044oia.1; Fri, 20 May 2016 20:05:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :date:message-id:subject:from:to:cc; bh=WaJLafaHwQwRASJEPOF5hiwJNesEUrwXem6OJVL5kGA=; b=BmOllatO4bSjj2blTywqvYapYVwOCFtAYevh8PM1J73KCkg3zqkYZjlRG6g1s1dwOr +Ql9fq67HUOybA0MtF0YBzmnNZNHjE/A6Rq9StKzjB4Cld/9kEiLU7VR12EHeYCKf0Pj Wi/znIOe42x0nefpnJZVCec5QgrWFrKZxea/G/FyI50qp//Wg7bNmHqvGjjvmIHUT2Hn UEffLV7+trg4sRYE8QOHZWGlFSUiihoNXnQ9kd0434SNuLWuvsfAyHFpZVFEce9i01v9 YfdX4lj6VFwuU+lX6LaHS2Z7EVaFMke6GapoPHnmPLcdlq1lri/KcfDmTS+IZv/2rFol TQ1w== X-Gm-Message-State: AOPr4FX/m++xW2PZ5wcd8qdh7UdsKRKr/pzCOVyrc7lKcsKXA5udg7iFusb4bcQPbvkezw== X-Received: by 10.202.221.214 with SMTP id u205mr3729167oig.94.1463795682225; Fri, 20 May 2016 18:54:42 -0700 (PDT) Received: from mail-it0-f52.google.com (mail-it0-f52.google.com. [209.85.214.52]) by smtp.gmail.com with ESMTPSA id t21sm6327962otd.20.2016.05.20.18.54.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 May 2016 18:54:42 -0700 (PDT) Received: by mail-it0-f52.google.com with SMTP id z123so2068313itg.0; Fri, 20 May 2016 18:54:41 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.36.131.67 with SMTP id d64mr4148923ite.34.1463795681407; Fri, 20 May 2016 18:54:41 -0700 (PDT) Reply-To: cem@FreeBSD.org Received: by 10.36.205.70 with HTTP; Fri, 20 May 2016 18:54:41 -0700 (PDT) In-Reply-To: <20160521103528.I1539@besplex.bde.org> References: <201605201950.u4KJoWA5028092@repo.freebsd.org> <20160521081930.I1098@besplex.bde.org> <20160521103528.I1539@besplex.bde.org> Date: Fri, 20 May 2016 18:54:41 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: svn commit: r300332 - in head/sys: amd64/amd64 i386/i386 From: Conrad Meyer To: Bruce Evans Cc: Konstantin Belousov , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.22 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: Sat, 21 May 2016 03:05:47 -0000 On Fri, May 20, 2016 at 6:10 PM, Bruce Evans wrote: > On Fri, 20 May 2016, Conrad Meyer wrote: > >> On Fri, May 20, 2016 at 4:02 PM, Bruce Evans wrote: >>> >>> On Fri, 20 May 2016, Konstantin Belousov wrote: >>> >>>> --- head/sys/i386/i386/sys_machdep.c Fri May 20 19:46:25 2016 >>>> (r300331) >>>> +++ head/sys/i386/i386/sys_machdep.c Fri May 20 19:50:32 2016 >>>> (r300332) >>>> @@ -315,8 +315,9 @@ i386_set_ioperm(td, uap) >>>> struct thread *td; >>>> struct i386_ioperm_args *uap; >>>> { >>>> - int i, error; >>>> char *iomap; >>>> + u_int i; >>>> + int error; >>>> >>>> if ((error = priv_check(td, PRIV_IO)) != 0) >>>> return (error); >>>> @@ -334,7 +335,8 @@ i386_set_ioperm(td, uap) >>>> return (error); >>>> iomap = (char *)td->td_pcb->pcb_ext->ext_iomap; >>>> >>>> - if (uap->start + uap->length > IOPAGES * PAGE_SIZE * NBBY) >>>> + if (uap->start > uap->start + uap->length || >>>> + uap->start + uap->length > IOPAGES * PAGE_SIZE * NBBY) >>>> return (EINVAL); >>>> >>>> for (i = uap->start; i < uap->start + uap->length; i++) { >>> >>> >>> I don't like using u_int for a small index. >> >> >> Why not? Indices are by definition non-negative so the fit seems natural. > > > Signed integers are easier to understand provided calculations with them > don't overflow. How? The rest of the argument seems to be, using u_int is bad because more unsigned is always bad. But I haven't seen a good reason to believe that is so. > Unsigned integers are not easier to understand if > calculations with them do overflow. That was the case here. > > Only indices relative to the base of an array are by definition > non-negative. For an array a[], it is valid to do p = &a[i] and then > use p[j] with negative j to get back before the i'th index. This is > sometimes useful. i + j must be >= 0, but is hard write correctly and > understand if either i or j is unsigned. (It can be arranged that the > addition wraps correctly, but this is basically re-implementing signed > arithmetic.) This has devolved from an array and index, to pointer arithmetic. The fact that C lets you do pointer arithmetic with array syntax doesn't help. The "real" indices are always non-negative. Best, Conrad