test_printf: Append strings more efficiently
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2073625 commit 507f98603607d43cb76ed39c370c4dc1ed6a94f9 Author: Matthew Wilcox (Oracle) <willy@infradead.org> Date: Tue, 19 Oct 2021 15:26:20 +0100 test_printf: Append strings more efficiently Use scnprintf instead of snprintf + strlen. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Petr Mladek <pmladek@suse.com> Reviewed-by: Yafang Shao <laoar.shao@gmail.com> Signed-off-by: Petr Mladek <pmladek@suse.com> Link: https://lore.kernel.org/r/20211019142621.2810043-5-willy@infradead.org Signed-off-by: Waiman Long <longman@redhat.com>
This commit is contained in:
parent
abccd95b35
commit
3a443a9a16
|
@ -614,8 +614,7 @@ page_flags_test(int section, int node, int zone, int last_cpupid,
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (flags & PAGEFLAGS_MASK) {
|
if (flags & PAGEFLAGS_MASK) {
|
||||||
snprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
|
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s", name);
|
||||||
size = strlen(cmp_buf);
|
|
||||||
append = true;
|
append = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -623,17 +622,14 @@ page_flags_test(int section, int node, int zone, int last_cpupid,
|
||||||
if (!pft[i].width)
|
if (!pft[i].width)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (append) {
|
if (append)
|
||||||
snprintf(cmp_buf + size, BUF_SIZE - size, "|");
|
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "|");
|
||||||
size = strlen(cmp_buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
flags |= (values[i] & pft[i].mask) << pft[i].shift;
|
flags |= (values[i] & pft[i].mask) << pft[i].shift;
|
||||||
snprintf(cmp_buf + size, BUF_SIZE - size, "%s=", pft[i].name);
|
size += scnprintf(cmp_buf + size, BUF_SIZE - size, "%s=",
|
||||||
size = strlen(cmp_buf);
|
pft[i].name);
|
||||||
snprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt,
|
size += scnprintf(cmp_buf + size, BUF_SIZE - size, pft[i].fmt,
|
||||||
values[i] & pft[i].mask);
|
values[i] & pft[i].mask);
|
||||||
size = strlen(cmp_buf);
|
|
||||||
append = true;
|
append = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue