From cdaa157c5b5002f5f1d872c65a8a6c0c480f5647 Mon Sep 17 00:00:00 2001 From: kre Date: Thu, 14 Mar 2024 19:38:56 +0000 Subject: [PATCH] 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). --- usr.bin/stat/stat.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usr.bin/stat/stat.c b/usr.bin/stat/stat.c index 34759aca03e1..dafb5f5ead70 100644 --- a/usr.bin/stat/stat.c +++ b/usr.bin/stat/stat.c @@ -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 #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;