NetBSD Problem Report #44128

From yamt@NetBSD.org  Mon Nov 22 04:44:43 2010
Return-Path: <yamt@NetBSD.org>
Received: by www.NetBSD.org (Postfix, from userid 1270)
	id 28A2263B95F; Mon, 22 Nov 2010 04:44:43 +0000 (UTC)
Message-Id: <20101122044443.28A2263B95F@www.NetBSD.org>
Date: Mon, 22 Nov 2010 04:44:43 +0000 (UTC)
From: yamt@NetBSD.org
Reply-To: yamt@NetBSD.org
To: gnats-bugs@NetBSD.org
Subject: stat(1) formatting bug (time_t related?)
X-Send-Pr-Version: 3.95

>Number:         44128
>Category:       bin
>Synopsis:       stat(1) formatting bug (time_t related?)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 22 04:45:03 +0000 2010
>Closed-Date:    Wed Nov 24 23:43:19 +0000 2010
>Last-Modified:  Wed Nov 24 23:43:19 +0000 2010
>Originator:     YAMAMOTO Takashi
>Release:        NetBSD
>Organization:

>Environment:

>Description:
	stat(1)'s format1() function seems to assume both of secs and nsecs
	are printf'able with "%d".  actually they are of time_t and long.

>How-To-Repeat:
	on 32bit machine,

	% stat -f "%Fa" /
	1290400248.000000000
>Fix:


>Release-Note:

>Audit-Trail:
From: David Holland <dholland-bugs@netbsd.org>
To: gnats-bugs@NetBSD.org
Cc: 
Subject: Re: bin/44128: stat(1) formatting bug (time_t related?)
Date: Mon, 22 Nov 2010 05:23:59 +0000

 On Mon, Nov 22, 2010 at 04:45:03AM +0000, yamt@NetBSD.org wrote:
  > 	stat(1)'s format1() function seems to assume both of secs and nsecs
  > 	are printf'able with "%d".  actually they are of time_t and long.

 How's this?

 Index: stat.c
 ===================================================================
 RCS file: /cvsroot/src/usr.bin/stat/stat.c,v
 retrieving revision 1.28
 diff -u -p -r1.28 stat.c
 --- stat.c	13 Apr 2009 23:02:36 -0000	1.28
 +++ stat.c	22 Nov 2010 05:21:02 -0000
 @@ -718,7 +718,6 @@ format1(const struct stat *st,
  #endif /* HAVE_STRUCT_STAT_ST_BIRTHTIME */
  		small = (sizeof(secs) == 4);
  		data = secs;
 -		small = 1;
  		tm = localtime(&secs);
  		(void)strftime(path, sizeof(path), timefmt, tm);
  		sdata = path;
 @@ -989,8 +988,9 @@ format1(const struct stat *st,
  				(void)snprintf(tmp, sizeof(tmp), "%d", size);
  				(void)strcat(lfmt, tmp);
  			}
 -			(void)strcat(lfmt, "d");
 -			return (snprintf(buf, blen, lfmt, secs));
 +			(void)strcat(lfmt, "lld");
 +			return (snprintf(buf, blen, lfmt,
 +			    (long long)secs));
  		}

  		/*
 @@ -1013,7 +1013,7 @@ format1(const struct stat *st,
  			(void)snprintf(tmp, sizeof(tmp), "%d", size);
  			(void)strcat(lfmt, tmp);
  		}
 -		(void)strcat(lfmt, "d");
 +		(void)strcat(lfmt, "lld");

  		/*
  		 * The stuff after the decimal point always needs zero
 @@ -1025,7 +1025,7 @@ format1(const struct stat *st,
  		 * We can "print" at most nine digits of precision.  The
  		 * rest we will pad on at the end.
  		 */
 -		(void)snprintf(tmp, sizeof(tmp), "%dd", prec > 9 ? 9 : prec);
 +		(void)snprintf(tmp, sizeof(tmp), "%dld", prec > 9 ? 9 : prec);
  		(void)strcat(lfmt, tmp);

  		/*
 @@ -1039,7 +1039,7 @@ format1(const struct stat *st,
  		 * Use the format, and then tack on any zeroes that
  		 * might be required to make up the requested precision.
  		 */
 -		l = snprintf(buf, blen, lfmt, secs, nsecs);
 +		l = snprintf(buf, blen, lfmt, (long long)secs, nsecs);
  		for (; prec > 9 && l < (int)blen; prec--, l++)
  			(void)strcat(buf, "0");
  		return (l);


 -- 
 David A. Holland
 dholland@netbsd.org

From: yamt@mwd.biglobe.ne.jp (YAMAMOTO Takashi)
To: gnats-bugs@NetBSD.org
Cc: gnats-admin@netbsd.org, netbsd-bugs@netbsd.org, yamt@NetBSD.org
Subject: Re: bin/44128: stat(1) formatting bug (time_t related?)
Date: Wed, 24 Nov 2010 22:34:19 +0000 (UTC)

 >  How's this?

 it looks good to me.

 YAMAMOTO Takashi

From: "David A. Holland" <dholland@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/44128 CVS commit: src/usr.bin/stat
Date: Wed, 24 Nov 2010 22:57:54 +0000

 Module Name:	src
 Committed By:	dholland
 Date:		Wed Nov 24 22:57:54 UTC 2010

 Modified Files:
 	src/usr.bin/stat: stat.c

 Log Message:
 Don't printf time_t with %d; fixes PR 44128 from yamt. With this change it
 successfully prints mtimes after 2038.


 To generate a diff of this commit:
 cvs rdiff -u -r1.28 -r1.29 src/usr.bin/stat/stat.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: dholland@NetBSD.org
State-Changed-When: Wed, 24 Nov 2010 23:43:19 +0000
State-Changed-Why:
fixed thanks


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.