From owner-freebsd-stable@FreeBSD.ORG Wed Feb 4 09:09:56 2015 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 93446D9F for ; Wed, 4 Feb 2015 09:09:56 +0000 (UTC) Received: from alogt.com (alogt.com [69.36.191.58]) (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 6730E1C5 for ; Wed, 4 Feb 2015 09:09:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=alogt.com; s=default; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Subject:Cc:To:From:Date; bh=oYdsT/HvU72K/apOSi7A1cDh8qG3ReyHKkPwtR/R/Y4=; b=yYG+zrtmv/eHvl/NJDXQYkfidMIWsJifDtRvDmBcD8RYJp+w7dYs54fCASxqDFraie7+j+jNSAfCxh6ybbtSW+iTL04rDmNbYATXC1h5A3ykHjtqVYHfJMlpW+FOA07J/9qyhdsE8lh9YmNKoyvnxSj9azLrFdtw0TEvuSS0il8=; Received: from [114.121.129.103] (port=17809 helo=B85M-HD3-0.alogt.com) by sl-508-2.slc.westdc.net with esmtpsa (TLSv1.2:AES128-GCM-SHA256:128) (Exim 4.84) (envelope-from ) id 1YIvy5-003Uqt-Jb; Wed, 04 Feb 2015 02:09:54 -0700 Date: Wed, 4 Feb 2015 17:09:47 +0800 From: Erich Dollansky To: John-Mark Gurney Subject: Re: top, fixed buffer length in utils.c Message-ID: <20150204170947.17764dff@B85M-HD3-0.alogt.com> In-Reply-To: <20150204074235.GX27103@funkthat.com> References: <20150201175159.7fa88d16@B85M-HD3-0.alogt.com> <20150203003307.GG27103@funkthat.com> <20150203200135.57c8c236@B85M-HD3-0.alogt.com> <20150204074235.GX27103@funkthat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - sl-508-2.slc.westdc.net X-AntiAbuse: Original Domain - freebsd.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - alogt.com X-Get-Message-Sender-Via: sl-508-2.slc.westdc.net: authenticated_id: erichsfreebsdlist@alogt.com X-Source: X-Source-Args: X-Source-Dir: Cc: freebsd-stable@freebsd.org X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Feb 2015 09:09:56 -0000 Hi, On Tue, 3 Feb 2015 23:42:35 -0800 John-Mark Gurney wrote: > Erich Dollansky wrote this message on Tue, Feb 03, 2015 at 20:01 > +0800: > > On Mon, 2 Feb 2015 16:33:07 -0800 > > John-Mark Gurney wrote: > > > > > Erich Dollansky wrote this message on Sun, Feb 01, 2015 at 17:51 > > > +0800: > > > > int can be 64 bits on a amd64 machine. Why is the author of this > > > > code so sure that we will never cross the 32 bit boundary? > > > > > > Per others, int is currently 32bits on all platforms we support... > > > > > > I guess adding: > > > CTASSERT(sizeof(int) <= 4); > > > > > > would help fix your concern? at least now the expectation is > > > codified and if it breaks, the build will break.. > > > > > of course. Either avoid the run-time problem or get an error message > > and things cannot create hidden problem. > > Ok, I've generated this patch: > Index: utils.c > =================================================================== > --- utils.c (revision 277938) > +++ utils.c (working copy) > @@ -58,6 +58,7 @@ char *str; > * ever convert will be 2^32-1, > which is 10 > * digits. > */ > +_Static_assert(sizeof(int) <= 4, "buffer too small for this sized > int"); > char *itoa(val) > Wait, shouldn't it the other way around? It will break when sizeof (int) is greater than 4? > > I couldn't use CTASSERT because including sys/param.h and sys/systm.h > per man page didn't work.. apparently for userland it's different and > requires additional headers... It appears that we define it in > sys/cdefs.h which gets included, so this work for both clang and > gcc... > > I'll commit it soon unless someone objects... > Thanks! Erich