Skip to content

Commit 507f986

Browse files
Matthew Wilcox (Oracle)pmladek
authored andcommitted
test_printf: Append strings more efficiently
Use scnprintf instead of snprintf + strlen. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Reviewed-by: Yafang Shao <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 5b358b0 commit 507f986

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

lib/test_printf.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -614,26 +614,22 @@ page_flags_test(int section, int node, int zone, int last_cpupid,
614614
int i;
615615

616616
if (flags & PAGEFLAGS_MASK) {
617-
snprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
618-
size = strlen(cmp_buf);
617+
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
619618
append = true;
620619
}
621620

622621
for (i = 0; i < ARRAY_SIZE(pft); i++) {
623622
if (!pft[i].width)
624623
continue;
625624

626-
if (append) {
627-
snprintf(cmp_buf + size, BUF_SIZE - size, "|");
628-
size = strlen(cmp_buf);
629-
}
625+
if (append)
626+
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "|");
630627

631628
flags |= (values[i] & pft[i].mask) << pft[i].shift;
632-
snprintf(cmp_buf + size, BUF_SIZE - size, "%s=", pft[i].name);
633-
size = strlen(cmp_buf);
634-
snprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt,
635-
values[i] & pft[i].mask);
636-
size = strlen(cmp_buf);
629+
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s=",
630+
pft[i].name);
631+
size += scnprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt,
632+
values[i] & pft[i].mask);
637633
append = true;
638634
}
639635

0 commit comments

Comments
 (0)