]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ALSA: jack: use scnprintf to improve parse_mask_bits
authorThorsten Blum <thorsten.blum@linux.dev>
Sun, 3 May 2026 10:11:02 +0000 (12:11 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 4 May 2026 11:28:35 +0000 (13:28 +0200)
Use the return value of scnprintf() to keep track of the current string
length and also replace strlcat() with scnprintf(). Return the string
length directly instead of calling strlen(buf).

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://patch.msgid.link/20260503101102.298782-2-thorsten.blum@linux.dev
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/jack.c

index 5e8a2f3f41966aed0a0a1c0310ee4df8fc3ccf0e..96e0733ede77834d90befaede879080dc7a797a9 100644 (file)
@@ -250,18 +250,15 @@ static const char * const jack_events_name[] = {
 /* the recommended buffer size is 256 */
 static int parse_mask_bits(unsigned int mask_bits, char *buf, size_t buf_size)
 {
+       int len = scnprintf(buf, buf_size, "0x%04x", mask_bits);
        int i;
 
-       scnprintf(buf, buf_size, "0x%04x", mask_bits);
-
        for (i = 0; i < ARRAY_SIZE(jack_events_name); i++)
-               if (mask_bits & (1 << i)) {
-                       strlcat(buf, " ", buf_size);
-                       strlcat(buf, jack_events_name[i], buf_size);
-               }
-       strlcat(buf, "\n", buf_size);
+               if (mask_bits & (1 << i))
+                       len += scnprintf(buf + len, buf_size - len, " %s", jack_events_name[i]);
+       len += scnprintf(buf + len, buf_size - len, "\n");
 
-       return strlen(buf);
+       return len;
 }
 
 static ssize_t jack_kctl_mask_bits_read(struct file *file,