Fix a trivial truncation case, and eliminate a corner case that might

print a nul character.
This commit is contained in:
atatat 2005-04-22 03:36:48 +00:00
parent f1fe53f0ac
commit fab1a5fa39

View File

@ -1,4 +1,4 @@
/* $NetBSD: stat.c,v 1.21 2005/01/13 00:53:14 jmc Exp $ */ /* $NetBSD: stat.c,v 1.22 2005/04/22 03:36:48 atatat Exp $ */
/* /*
* Copyright (c) 2002 The NetBSD Foundation, Inc. * Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -42,7 +42,7 @@
#include <sys/cdefs.h> #include <sys/cdefs.h>
#if !defined(lint) #if !defined(lint)
__RCSID("$NetBSD: stat.c,v 1.21 2005/01/13 00:53:14 jmc Exp $"); __RCSID("$NetBSD: stat.c,v 1.22 2005/04/22 03:36:48 atatat Exp $");
#endif #endif
#if ! HAVE_NBTOOL_CONFIG_H #if ! HAVE_NBTOOL_CONFIG_H
@ -357,7 +357,7 @@ output(const struct stat *st, const char *file,
const char *statfmt, int fn, int nonl, int quiet) const char *statfmt, int fn, int nonl, int quiet)
{ {
int flags, size, prec, ofmt, hilo, what; int flags, size, prec, ofmt, hilo, what;
char buf[PATH_MAX]; char buf[PATH_MAX + 4 + 1];
const char *subfmt; const char *subfmt;
int nl, t, i; int nl, t, i;
@ -526,7 +526,7 @@ output(const struct stat *st, const char *file,
buf, sizeof(buf), buf, sizeof(buf),
flags, size, prec, ofmt, hilo, what); flags, size, prec, ofmt, hilo, what);
for (i = 0; i < t && i < sizeof(buf); i++) for (i = 0; i < t && i < sizeof(buf) - 1; i++)
addchar(stdout, buf[i], &nl); addchar(stdout, buf[i], &nl);
continue; continue;