[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <2032D1DB-821B-4B6B-882C-0E77E5582D5F@fb.com>
Date: Sun, 1 Nov 2020 18:06:41 +0000
From: Song Liu <songliubraving@...com>
To: David Laight <David.Laight@...LAB.COM>
CC: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
stable <stable@...r.kernel.org>,
Jin Yao <yao.jin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Arnaldo Carvalho de Melo <acme@...hat.com>,
"Arnaldo Carvalho de Melo" <acme@...nel.org>
Subject: Re: [PATCH] perf: increase size of buf in perf_evsel__hists_browse()
> On Oct 31, 2020, at 4:27 AM, David Laight <David.Laight@...LAB.COM> wrote:
>
> From: Song Liu
>> Sent: 30 October 2020 23:55
>>
>> Making perf with gcc-9.1.1 generates the following warning:
>>
>> CC ui/browsers/hists.o
>> ui/browsers/hists.c: In function 'perf_evsel__hists_browse':
>> ui/browsers/hists.c:3078:61: error: '%d' directive output may be \
>> truncated writing between 1 and 11 bytes into a region of size \
>> between 2 and 12 [-Werror=format-truncation=]
>>
>> 3078 | "Max event group index to sort is %d (index from 0 to %d)",
>> | ^~
>> ui/browsers/hists.c:3078:7: note: directive argument in the range [-2147483648, 8]
>> 3078 | "Max event group index to sort is %d (index from 0 to %d)",
>> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> In file included from /usr/include/stdio.h:937,
>> from ui/browsers/hists.c:5:
>>
>> IOW, the string in line 3078 might be too long for buf[] of 64 bytes.
>>
>> Fix this by increasing the size of buf[] to 128.
>
> ISTM that something should be unsigned so that the bound check
> that puts an upper bound of 8 implies a lower bound.
>
> David
Changing both "%d" in this line to "%u" does fix the warning. But we
are printing "evsel->core.nr_members - 1" here, and nr_members is
signed int. So I feel more comfortable keep the "%d"s and increase
the buffer size.
Thanks,
Song
Powered by blists - more mailing lists