Skip to contentSkip to conversation

lib/vsprintf: Improve vsprintf + sprintf function comments

PATCH RESEND In review Thorsten Blum 3 participants 5 messages Nov 3, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 lib/vsprintf: Improve vsprintf + sprintf function comments

Clarify that the return values of vsprintf() and sprintf() exclude the trailing NUL character.

---
 lib/vsprintf.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
lib/vsprintf.c +4 -4
index eb0cb11d0d12..e49f350ee549 100644
@@ -3054,8 +3054,8 @@ EXPORT_SYMBOL(scnprintf);
  * @fmt: The format string to use
  * @args: Arguments for the format string
  *
- * The function returns the number of characters written
- * into @buf. Use vsnprintf() or vscnprintf() in order to avoid
+ * The return value is the number of characters written into @buf not including
+ * the trailing '\0'. Use vsnprintf() or vscnprintf() in order to avoid
  * buffer overflows.
  *
  * If you're not already dealing with a va_list consider using sprintf().
@@ -3074,8 +3074,8 @@ EXPORT_SYMBOL(vsprintf);
  * @fmt: The format string to use
  * @...: Arguments for the format string
  *
- * The function returns the number of characters written
- * into @buf. Use snprintf() or scnprintf() in order to avoid
+ * The return value is the number of characters written into @buf not including
+ * the trailing '\0'. Use snprintf() or scnprintf() in order to avoid
  * buffer overflows.
  *
  * See the vsnprintf() documentation for format string extensions over C99.
Signature · 1 line
2.51.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Thorsten Blum

Clarify that the return values of vsprintf() and sprintf() exclude the trailing NUL character.

I dunno if we need this clarification, but I'm not against it either, FWIW,

if it helps somebody.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 2 lines · Thorsten Blum

Clarify that the return values of vsprintf() and sprintf() exclude the trailing NUL character.

I dunno if we need this clarification, but I'm not against it either, FWIW,

if it helps somebody.

Thanks. It would have helped me :)

maintainer
#4 lore raw
In reply to Thorsten Blum
Quoted 4 lines · Thorsten Blum

Clarify that the return values of vsprintf() and sprintf() exclude the trailing NUL character.

JFYI, the patch has been comitted into printk/linux.git, branch for-6.19.

Best Regards,
Petr

PS: The patch was trivial so I was not waiting for any additional
feedback. And better to do not forget about the patch again ;-)