lkml.org 
[lkml]   [2020]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [PATCH v2 02/10] netfilter: Avoid assigning 'const' pointer to non-const pointer
Date
From: Nick Desaulniers
> Sent: 24 January 2020 17:20
...
> > > Good thing it's the variable being modified was not declared const; I
> > > get spooked when I see -Wdiscarded-qualifiers because of Section
> > > 6.7.3.6 of the ISO C11 draft spec:
> > >
> > > ```
> > > If an attempt is made to modify an object defined with a const-qualified
> > > type through use of an lvalue with non-const-qualified type,
> > > the behavior is undefined.

Well some old systems had small integer constants at fixes addresses.
So 'const int one = 1;' would be a reference to the global constant.
An assignment like '*(int *)&one = 2;' would change the value of the
system-wide 'one' constant'.

Pretty much 'undefined'.

But no excuse for the compiler just discarding the code.

I suspect that the code to remove 'const' needs to 'launder' the value
through a suitable integer type.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
\
 
 \ /
  Last update: 2020-01-27 13:05    [W:1.647 / U:0.332 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site