From owner-svn-src-all@freebsd.org Thu Apr 21 17:30:42 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 E9430B17B72; Thu, 21 Apr 2016 17:30:42 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (heidi.turbocat.net [88.198.202.214]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A73851AA5; Thu, 21 Apr 2016 17:30:42 +0000 (UTC) (envelope-from hps@selasky.org) Received: from laptop015.home.selasky.org (unknown [62.141.129.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id 2309F1FE024; Thu, 21 Apr 2016 19:30:40 +0200 (CEST) Subject: Re: svn commit: r298420 - head/sys/geom To: Alan Somers , Ngie Cooper References: <201604211643.u3LGhFpR057982@repo.freebsd.org> Cc: "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" From: Hans Petter Selasky Message-ID: <57190F03.2080703@selasky.org> Date: Thu, 21 Apr 2016 19:33:55 +0200 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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: Thu, 21 Apr 2016 17:30:43 -0000 On 04/21/16 19:26, Alan Somers wrote: > On Thu, Apr 21, 2016 at 11:09 AM, Ngie Cooper wrote: > >> On Thu, Apr 21, 2016 at 10:08 AM, Ngie Cooper >> wrote: >>> On Thu, Apr 21, 2016 at 9:43 AM, Alan Somers >>>> { >>>> struct g_geom *gp; >>>> struct g_provider *pp; >>>> + char devnamebuf[128]; >>> >>> Why 128? Also, why not sbuf? >>> >>>> gp = dp->d_geom; >>>> if (gp != NULL) >>>> LIST_FOREACH(pp, &gp->provider, provider) >>>> (void)g_attr_changed(pp, attr, flag); >>>> + snprintf(devnamebuf, 128, "devname=%s%d", dp->d_name, >> dp->d_unit); >>> >>> Why not sizeof(devnamebuf) ? >> >> Also: this doesn't NUL terminate devnamebuf; it really should >> (otherwise, boom... crash in geom)... >> > > snprintf(3) says "The output is always null-terminated." and it looks like > the kernel version does the same thing at subr_prf.c:560. Am I missing > something? > Hi, The code is correct, though it is good practice to use sizeof() like Ngie suggests or define the size of the buffer like a macro. grep -rE "snprintf.*sizeof" /usr/src/sys/dev --HPS