While the change in 1.51 certainly retained binary compat with

what was in 1.50 (while silencing LINT) - it was clearly not the
correct change to make.   The code used !FLAG_POUND where it
clearly meant ~FLAG_POUND ... the former is 0, so &= 0 could
be replaced by =0 changing nothing.   But that's not what it
should have been doing, other flags should not have been
removed here, just FLAG_POUND.

This problem seems to have existed since support for %#s
was first added in 2011, which kind of suggests how rarely
that format, particularly with other flags (like %#-s)
has ever been used (with no other flags, the bug would not
be noticed).
This commit is contained in:
kre 2024-03-14 19:38:56 +00:00
parent fb93b87aa0
commit cdaa157c5b
1 changed files with 3 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: stat.c,v 1.51 2024/03/14 00:07:20 rillig Exp $ */
/* $NetBSD: stat.c,v 1.52 2024/03/14 19:38:56 kre Exp $ */
/*
* Copyright (c) 2002-2011 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
__RCSID("$NetBSD: stat.c,v 1.51 2024/03/14 00:07:20 rillig Exp $");
__RCSID("$NetBSD: stat.c,v 1.52 2024/03/14 19:38:56 kre Exp $");
#endif
#if ! HAVE_NBTOOL_CONFIG_H
@ -1077,7 +1077,7 @@ format1(const struct stat *st,
* First prefixlen chars are not encoded.
*/
if ((flags & FLAG_POUND) != 0 && ofmt == FMTF_STRING) {
flags = 0;
flags &= ~FLAG_POUND;
strncpy(visbuf, sdata, prefixlen);
/* Avoid GCC warnings. */
visbuf[prefixlen] = 0;