From owner-freebsd-stable@FreeBSD.ORG Sun Feb 1 14:15:12 2015 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 3367CF51 for ; Sun, 1 Feb 2015 14:15:12 +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 0D90E9F8 for ; Sun, 1 Feb 2015 14:15:11 +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=bXGYP5gKwDbzOr7xAcH+SSvolD5Xy2WNIk7C2Qk0aCo=; b=laMocuqRx/ms9qx2JWfFHRZH6H5CtEfBtBpdqijpMC4uwwpP1EGB7UqRtQ0Fsn6Urya0gPWcODi08Gp/nft/lFNScO7mfjNwMSUSEHi9TRvjLW6jkPd4xcLDHuqilWq1YvNj8f18cXH8nICCwcOE7XrtbY85Kty24xjEDuq8IB0=; Received: from [114.121.161.125] (port=41631 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 1YHvIr-002ytC-Dw; Sun, 01 Feb 2015 07:15:10 -0700 Date: Sun, 1 Feb 2015 22:14:21 +0800 From: Erich Dollansky To: Michelle Sullivan Subject: Re: top, fixed buffer length in utils.c Message-ID: <20150201221421.164051e2@B85M-HD3-0.alogt.com> In-Reply-To: <54CE26AE.10005@sorbs.net> References: <20150201175159.7fa88d16@B85M-HD3-0.alogt.com> <20150201195722.68845794@akips.com> <54CE26AE.10005@sorbs.net> 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, Paul Koch 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: Sun, 01 Feb 2015 14:15:12 -0000 Hi, On Sun, 01 Feb 2015 14:14:22 +0100 Michelle Sullivan wrote: > Paul Koch wrote: > > On Sun, 1 Feb 2015 17:51:59 +0800 > > Erich Dollansky wrote: > > > > > >> Hi, > >> > >> I came across this here in utils.c which is part of top: > >> > >> > >> /* > >> * How do we know that 16 will suffice? > >> * Because the biggest number that we > >> will > >> * ever convert will be 2^32-1, which > >> is 10 > >> * digits. > >> */ > >> > >> char *itoa(val) > >> > >> register int val; > >> > >> 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? > >> > >> Erich > >> > > > > I thought an 'int' was a 32bit number on amd64 arch. > > > > IIRC reading at least one of the C 'standards' (don't recall if it was > ANSI or C99) sizeof(int) has to be determined at runtime time because > it could be 8, or 16 bit and that wasn't dependent on the arch type, int can be anything from 16 bits to the 'natural' size of the CPU registers. > it was dependent on the compiler (and maybe other factors.) Yes, it is a decision the the compiler supplier has to do. > Unfortunately when I queried this with a Uni Prof as to why, I was > told, mostly its 16 bits but you should always check if you have > something that cares (where it matters.) > It is some time ago that it was 16 bits as the standard. The standard just says that int is not shorter than a short int and not longer than a long int. Erich