Don't shadow 'i' in conf_ports()
The counter 'i' is used in a number of places in conf_ports(), but in one of those we unnecessarily shadow it in an inner scope. We could re-use the same 'i' every time, but each use is logically separate, so instead remove the outer declaration and declare it locally in each of the clauses where we need it. While we're there change it from a signed to unsigned int, since it's used to iterate over port numbers which are generally treated as unsigned. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
eb5e123038
commit
ab96da98cd
1 changed files with 5 additions and 2 deletions
7
conf.c
7
conf.c
|
@ -183,7 +183,6 @@ static int conf_ports(const struct ctx *c, char optname, const char *optarg,
|
||||||
char buf[BUFSIZ], *spec, *p;
|
char buf[BUFSIZ], *spec, *p;
|
||||||
sa_family_t af = AF_UNSPEC;
|
sa_family_t af = AF_UNSPEC;
|
||||||
bool exclude_only = true;
|
bool exclude_only = true;
|
||||||
unsigned i;
|
|
||||||
|
|
||||||
if (!strcmp(optarg, "none")) {
|
if (!strcmp(optarg, "none")) {
|
||||||
if (fwd->mode)
|
if (fwd->mode)
|
||||||
|
@ -200,7 +199,7 @@ static int conf_ports(const struct ctx *c, char optname, const char *optarg,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(optarg, "all")) {
|
if (!strcmp(optarg, "all")) {
|
||||||
int i;
|
unsigned i;
|
||||||
|
|
||||||
if (fwd->mode || c->mode != MODE_PASST)
|
if (fwd->mode || c->mode != MODE_PASST)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -247,6 +246,7 @@ static int conf_ports(const struct ctx *c, char optname, const char *optarg,
|
||||||
p = spec;
|
p = spec;
|
||||||
do {
|
do {
|
||||||
struct port_range xrange;
|
struct port_range xrange;
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
if (*p != '~') {
|
if (*p != '~') {
|
||||||
/* Not an exclude range, parse later */
|
/* Not an exclude range, parse later */
|
||||||
|
@ -268,6 +268,8 @@ static int conf_ports(const struct ctx *c, char optname, const char *optarg,
|
||||||
} while ((p = next_chunk(p, ',')));
|
} while ((p = next_chunk(p, ',')));
|
||||||
|
|
||||||
if (exclude_only) {
|
if (exclude_only) {
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
for (i = 0; i < PORT_EPHEMERAL_MIN; i++) {
|
for (i = 0; i < PORT_EPHEMERAL_MIN; i++) {
|
||||||
if (bitmap_isset(exclude, i))
|
if (bitmap_isset(exclude, i))
|
||||||
continue;
|
continue;
|
||||||
|
@ -287,6 +289,7 @@ static int conf_ports(const struct ctx *c, char optname, const char *optarg,
|
||||||
p = spec;
|
p = spec;
|
||||||
do {
|
do {
|
||||||
struct port_range orig_range, mapped_range;
|
struct port_range orig_range, mapped_range;
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
if (*p == '~')
|
if (*p == '~')
|
||||||
/* Exclude range, already parsed */
|
/* Exclude range, already parsed */
|
||||||
|
|
Loading…
Reference in a new issue