Skip to contentSkip to conversation

tracing: Replace strncpy with memcpy for fixed-length substring copy

PATCH New Siddarth G 1 participant 1 message Mar 25, 2025 Tracing

lore
Share & tools
lore

Siddarth G

author
#0 lore raw

PATCH 1/1 tracing: Replace strncpy with memcpy for fixed-length substring copy

checkpatch.pl reports the following warning:
WARNING: Prefer strscpy, strscpy_pad, or __nonstring over strncpy (see: https://github.com/KSPP/linux/issues/90)

In synth_field_string_size(), replace strncpy() with memcpy() to copy 'len' characters from 'start' to 'buf'. The code manually adds a NUL terminator after the copy, making memcpy safe here.

---
 kernel/trace/trace_events_synth.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_synth.c +1 -1
index e3f7d09e5512..1aaa9a5e2aca 100644
@@ -207,7 +207,7 @@ static int synth_field_string_size(char *type)
 	if (len == 0)
 		return 0; /* variable-length string */
 
-	strncpy(buf, start, len);
+	memcpy(buf, start, len);
 	buf[len] = '\0';
 
 	err = kstrtouint(buf, 0, &size);
Signature · 1 line
2.43.0