iptables: Constify option struct
PATCH 1/1 iptables: Constify option struct
The struct of type option is only used to initialise a field inside the xtables_globals struct and is not modified anywhere. Done using following coccinelle semantic patch
@r1 disable optional_qualifier@
identifier s,i;
position p;
@@
static struct option i@p[] ={...};
@ok1@
identifier r1.i;
expression e;
position p;
@@
e = i@p
@bad@
position p != {r1.p,ok1.p};
identifier r1.i;
@@
e@i@p
@depends on !bad disable optional_qualifier@
identifier r1.i;
@@
static
+const
struct option i[] = { ... };
Signed-off-by Harsha Sharma <[email protected]>
--- iptables/ip6tables.c | 2 +- iptables/iptables.c | 2 +- iptables/xtables-eb.c | 2 +- iptables/xtables.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
iptables/ip6tables.c +1 -1
@@ -78,7 +78,7 @@ static const char optflags[]static const char unsupported_rev[] =" [unsupported revision]" ; -static struct option original_opts[] = { +static const struct option original_opts[] = { {.name ="append" , .has_arg =1 , .val ='A' }, {.name ="delete" , .has_arg =1 , .val ='D' }, {.name ="check" , .has_arg =1 , .val ='C' },
iptables/iptables.c +1 -1
@@ -75,7 +75,7 @@ static const char optflags[]static const char unsupported_rev[] =" [unsupported revision]" ; -static struct option original_opts[] = { +static const struct option original_opts[] = { {.name ="append" , .has_arg =1 , .val ='A' }, {.name ="delete" , .has_arg =1 , .val ='D' }, {.name ="check" , .has_arg =1 , .val ='C' },
iptables/xtables-eb.c +1 -1
@@ -247,7 +247,7 @@ static int get_current_chain(const char *chain)/* Default command line options. Do not mess around with the already * assigned numbers unless you know what you are doing */ -static struct option ebt_original_options[] = +static const struct option ebt_original_options[] = { {"append" , required_argument,0 ,'A' }, {"insert" , required_argument,0 ,'I' },
iptables/xtables.c +1 -1
@@ -59,7 +59,7 @@ static const char cmdflags[] = { 'I', 'D', 'D', 'R', 'A', 'L', 'F', 'Z',static const char optflags[] = {'n' ,'s' ,'d' ,'p' ,'j' ,'v' ,'x' ,'i' ,'o' ,'0' ,'c' ,'f' }; -static struct option original_opts[] = { +static const struct option original_opts[] = { {.name ="append" , .has_arg =1 , .val ='A' }, {.name ="delete" , .has_arg =1 , .val ='D' }, {.name ="check" , .has_arg =1 , .val ='C' },
Signature · 1 line
1.9.1
Quoted 3 lines · Harsha Sharma
The struct of type option is only used to initialise a field inside the
xtables_globalsstruct and is not modified anywhere. Done using following coccinelle semantic patch
Applied, thanks.