conf_ports_range_except() checks that it hasn't been asked to map port 0,
which generally won't work. However, there's only one callsite that
doesn't statically pass a non-zero value here. Change the check to an
assert() and move the actual error message to that callsite. This will
allow further cleanups later.
Signed-off-by: David Gibson
---
conf.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/conf.c b/conf.c
index e5baf8ee..dc9468c2 100644
--- a/conf.c
+++ b/conf.c
@@ -151,10 +151,7 @@ static void conf_ports_range_except(const struct ctx *c, char optname,
unsigned base, i;
uint8_t proto;
- if (first == 0) {
- die("Can't forward port 0 for option '-%c %s'",
- optname, optarg);
- }
+ assert(first != 0);
if (optname == 't' || optname == 'T')
proto = IPPROTO_TCP;
@@ -404,6 +401,11 @@ static void conf_ports(const struct ctx *c, char optname, const char *optarg,
if ((*p != '\0') && (*p != ',')) /* Garbage after the ranges */
goto bad;
+ if (orig_range.first == 0) {
+ die("Can't forward port 0 for option '-%c %s'",
+ optname, optarg);
+ }
+
conf_ports_range_except(c, optname, optarg, fwd,
addr, ifname,
orig_range.first, orig_range.last,
--
2.53.0