netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Junrui Luo <moonafterrain@outlook.com>
Cc: linux-kernel@vger.kernel.org, pmladek@suse.com,
	rostedt@goodmis.org, akpm@linux-foundation.org, tiwai@suse.com,
	perex@perex.cz, linux-sound@vger.kernel.org, mchehab@kernel.org,
	awalls@md.metrocast.net, linux-media@vger.kernel.org,
	davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
	pabeni@redhat.com, netdev@vger.kernel.org
Subject: Re: [PATCH 1/4] lib/sprintf: add scnprintf_append() helper function
Date: Fri, 7 Nov 2025 11:34:01 +0200	[thread overview]
Message-ID: <aQ29CSOtOG_tmeIp@smile.fi.intel.com> (raw)
In-Reply-To: <SYBPR01MB788110A77D7F0F7A27F0974FAFC3A@SYBPR01MB7881.ausprd01.prod.outlook.com>

On Fri, Nov 07, 2025 at 01:16:13PM +0800, Junrui Luo wrote:
> Add a new scnprintf_append() helper function that appends formatted
> strings to an existing buffer.
> 
> The function safely handles buffer bounds and returns the total length
> of the string, making it suitable for chaining multiple append operations.

This won't work as expected in the *printf() functions.

...

> +/**
> + * scnprintf_append - Append a formatted string to a buffer

The name with _cat would be probably closer to the strcpy()/strcat().
OTOH we have pr_cont(), so perhaps I would name this scnprintf_cont().

> + * @buf: The buffer to append to (must be null-terminated)

Yeah, and must be not NULL which is no go. The *printf() should tolerate
the (buf = NULL, size = 0) input.

> + * @size: The size of the buffer
> + * @fmt: Format string
> + * @...: Arguments for the format string
> + *
> + * This function appends a formatted string to an existing null-terminated

Use the form of "null-terminated" used in the file. Perhaps you want to update
the existing one(s), just make sure there is some consistency.

> + * buffer. It is safe to use in a chain of calls, as it returns the total
> + * length of the string.
> + *
> + * Returns: The total length of the string in @buf
> + */
> +int scnprintf_append(char *buf, size_t size, const char *fmt, ...)
> +{
> +	va_list args;
> +	size_t len;

> +	len = strnlen(buf, size);
> +	if (len >= size)

How can it be '>' ?

> +		return len;

> +	va_start(args, fmt);
> +	len += vscnprintf(buf + len, size - len, fmt, args);
> +	va_end(args);
> +	return len;
> +}

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2025-11-07  9:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20251107051616.21606-1-moonafterrain@outlook.com>
2025-11-07  5:16 ` [PATCH 1/4] lib/sprintf: add scnprintf_append() helper function Junrui Luo
2025-11-07  5:38   ` Andrew Morton
2025-11-07  9:12     ` David Laight
2025-11-07  9:35       ` Andy Shevchenko
2025-11-07 12:52         ` Petr Mladek
2025-11-07 17:51           ` David Laight
2025-11-10 14:13             ` Petr Mladek
2025-11-11 13:31               ` Junrui Luo
2025-11-12  9:39                 ` Petr Mladek
2025-11-08  0:11       ` Andrew Morton
2025-11-08  9:11         ` Takashi Iwai
2025-11-07  9:34   ` Andy Shevchenko [this message]
2025-11-07  5:16 ` [PATCH 2/4] ALSA: wavefront: use scnprintf_append for longname construction Junrui Luo
2025-11-07  5:16 ` [PATCH 3/4] media: ivtv: use scnprintf_append for i2c adapter name Junrui Luo
2025-11-07  5:16 ` [PATCH 4/4] net: qede: use scnprintf_append for version string Junrui Luo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aQ29CSOtOG_tmeIp@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=awalls@md.metrocast.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=moonafterrain@outlook.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=perex@perex.cz \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).