Subject: Re: [PATCH next] netfilter: nf_conntrack_h323: Correct indentation when H323_TRACE defined

From: David Laight <[email-masked]>
Date: Fri, 27 Mar 2026 09:51:58 +0000

On Fri, 27 Mar 2026 11:24:50 +0200
Andy Shevchenko <[email-masked]> wrote:

> On Thu, Mar 26, 2026 at 10:18:09PM +0000, David Laight wrote:
> > On Thu, 26 Mar 2026 21:24:39 +0100
> > Pablo Neira Ayuso <[email-masked]> wrote:  
> > > On Thu, Mar 26, 2026 at 08:18:19PM +0000, [email-masked] wrote:  
> > > > 
> > > > The trace lines are indented using PRINT("%*.s", xx, " ").
> > > > Userspace will treat this as "%*.0s" and will output no characters
> > > > when 'xx' is zero, the kernel treats it as "%*s" and will output
> > > > a single ' ' - which is probably what is intended.
> > > > 
> > > > Change all the formats to "%*s" removing the default precision.
> > > > This gives a single space indent when level is zero.    
> > > 
> > > Do you have a setup using this helper? Or you just found this via
> > > visual inspection?  
> > 
> > Found with grep looking for places which might be affected by 'fixing'
> > the kernel printf code to be POSIX compliant.  
> 
> Do we have the respective test case in printf_kunit?
> 

There are definitely related ones and this comment:

static void
test_string(struct kunit *kunittest)
{
[...]
	/*
	 * POSIX and C99 say that a negative precision (which is only
	 * possible to pass via a * argument) should be treated as if
	 * the precision wasn't present, and that if the precision is
	 * omitted (as in %.s), the precision should be taken to be
	 * 0. However, the kernel's printf behave exactly opposite,
	 * treating a negative precision as 0 and treating an omitted
	 * precision specifier as if no precision was given.
	 *
	 * These test cases document the current behaviour; should
	 * anyone ever feel the need to follow the standards more
	 * closely, this can be revisited.
	 */
	test("    ", "%4.*s", -5, "123456");
[...]
}

I suspect whoever wrote the tests found the code was non-conformant.
But there isn't a comment in the snprintf() code itself.
I've not checked what the kernel code does (I've just written/fixed all
this for nolibc - the kernel will fail the nolibc tests).

	David