Thread (41 messages) 41 messages, 12 authors, 2020-02-10

RE: [PATCH v2 02/10] netfilter: Avoid assigning 'const' pointer to non-const pointer

From: David Laight <hidden>
Date: 2020-01-27 12:04:44
Also in: lkml

From: Nick Desaulniers
Sent: 24 January 2020 17:20
...
quoted
quoted
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)
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help