Re: [PATCH] staging: greybus: audio: fix snprintf truncation errors

From: Dan Carpenter

Date: Sat Jun 06 2026 - 03:09:04 EST


On Fri, Jun 05, 2026 at 08:28:56PM +0100, Rhys Tumelty wrote:
> change snprintf() to scnprintf() in both gbaudio_tplg_create_widget()
> and gbaudio_tplg_process_kcontrols() to prevent potential string
> truncation warnings when prefixing the device id to the control name.
>

This commit message is unclear. My understanding is that snprintf()
is complaining that the array size of w->name is less than the array
size of "GB %d %s" plus the array size of temp_name. This is a W=1
complaint.

I hate this warning. We use snprintf() to deliberately truncate
the string. Now it's complaining that the string might be truncated.
Oh no! What we want to happen might happen! This is the same argument
that people used to block safer alternatives to strcpy() into glibc
because "it's still going to truncate the string and that's equally
bad as a root exploit!"

First of all, the string is not going to be truncated. (I haven't
looked). Second of all, this warning makes no sense in the kernel.
I have never once had a bug which I failed to debug because the
last two bytes in a string were truncated. There has never been a
scenario where I was looking through dmesg and snprintf() truncated
some bytes so I couldn't guess what I was looking at.

So your solution is to change it to scnprintf() which is kernel only
and GCC doesn't know about it... I bet GCC eventually learns about
scnprintf() and it eventually becomes a warning again.

A better solution is to disable that annoying check.

regards,
dan carpenter