NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: bin/44128: stat(1) formatting bug (time_t related?)



The following reply was made to PR bin/44128; it has been noted by GNATS.

From: David Holland <dholland-bugs%netbsd.org@localhost>
To: gnats-bugs%NetBSD.org@localhost
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@localhost 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@localhost
 


Home | Main Index | Thread Index | Old Index