[LTP] [PATCH v2 4/5] API/cgroup: Make tst_cgroup_group_mk sprintf like

Richard Palethorpe rpalethorpe@suse.de
Mon Feb 7 09:44:33 CET 2022


Hello,

Cyril Hrubis <chrubis@suse.cz> writes:

> Hi!
>> Seems this is too strict for some compiling.  e.g.
>> 
>> cfs_bandwidth01.c: In function ???mk_cpu_cgroup???:
>> cfs_bandwidth01.c:64:9: error: format not a string literal and no format
>> arguments [-Werror=format-security]
>>    64 |         *cg = tst_cgroup_group_mk(cg_parent, cg_child_name);
>>       |         ^
>> cc1: some warnings being treated as errors
>> make: *** [../../../../include/mk/rules.mk:37: cfs_bandwidth01] Error 1
>> 
>> gcc version 11.2.1 20211203 (Red Hat 11.2.1-7) (GCC)

Sorry I should have done a full rebuild.

>
> Ah, right, that's the __attribute__ format printf. I guess that we would
> have to live with changing all the calls to
> tst_cgroup_group_mk(foo, "%s", child_name)

Actually it's just calls where the compiler can't tell if child_name is
a string literal. Looking at vsnprintf in stdio.h it seems like we
should be able to add `__attribute__((format(printf,3,0)))` to
mk_cpu_cgroup and then cg_child_name should be guaranteed to be a string
literal. Alas it doesn't work, niether does the format_arg attribute in
this case.

I guess if I made a va arg version of tst_cgroup_group_mk then it would
work, but this is starting to get silly. So I'll just do "%s".

-- 
Thank you,
Richard.


More information about the ltp mailing list