[igt-dev] [PATCH v2] tests/i915_pm_rpm: improved strictness and verbosity of i2c subtest
Ser, Simon
simon.ser at intel.com
Mon Jun 17 14:22:12 UTC 2019
On Mon, 2019-06-17 at 17:09 +0300, Ville Syrjälä wrote:
> On Mon, Jun 17, 2019 at 04:40:21PM +0300, Petri Latvala wrote:
> > On Mon, Jun 17, 2019 at 04:26:45PM +0300, Ville Syrjälä wrote:
> > > On Mon, Jun 17, 2019 at 10:05:29AM +0000, Vasilev, Oleg wrote:
> > > > Hi,
> > > >
> > > > Thank you for the review. I've sent an updated patch.
> > > >
> > > > On Fri, 2019-06-14 at 18:30 +0300, Ville Syrjälä wrote:
> > > > > On Thu, Jun 13, 2019 at 04:06:23PM +0300, Oleg Vasilev wrote:
> > > > > > +static void format_hex_string(unsigned char edid[static
> > > > > > EDID_LENGTH],
> > > > > > + char buf[static EDID_LENGTH * 5 + 1])
> > > > >
> > > > > What's the deal with those 'static's?
> > > >
> > > > This enforces an array size to be at least EDID_LENGTH.
> > > >
> > > > https://hamberg.no/erlend/posts/2013-02-18-static-array-indices.html
> > >
> > > Interesting. Ugly, but interesting.
> > >
> > > Doesn't look like gcc cares about this at all though. I doesn't even
> > > care if I do silly things like:
> > >
> > > int foo(int x[static 8])
> > > {
> > > return x[20];
> > > }
> > >
> > > I guess clang is better?
> >
> > The 8 means there's at least 8 elements, it doesn't restrict there being more.
>
> Ah, yes. That was a bad example. But it doesn't warn if I call it
> with an array smaller than the 8 elemets either.
>
> > And it's mostly for the call site. Try calling foo(NULL) now.
>
> No warnings.
>
> So unless there's a new -W knob for this which isn't part of -Wall
> -Wextra this seems pointless with gcc (well, at least gcc 8.3).
Indeed. This seems like a GCC bug [1]. Clang gives a better warning.
[1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50584
> cat test.c
int foo(char arr[static 42]) {
return arr[1];
}
int main() {
char arr[1];
return foo(arr);
}
> gcc -Wall -Wextra test.c
> clang -Wall -Wextra test.c
test.c:7:9: warning: array argument is too small; contains 1 elements,
callee requires at least 42
[-Warray-bounds]
return foo(arr);
^ ~~~
test.c:1:14: note: callee declares array parameter as static here
int foo(char arr[static 42]) {
^ ~~~~~~~~~~~
1 warning generated.
More information about the igt-dev
mailing list