[RFC PATCH 01/14] config: refactor parse_leasetime() - branch amount remains same

Paul Donald newtwen+github at gmail.com
Thu May 9 15:30:33 PDT 2024


From: Paul Donald <newtwen at gmail.com>

Also make 's' value a noop.

Signed-off-by: Paul Donald <newtwen at gmail.com>
---
 src/config.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/config.c b/src/config.c
index 62d4857..346d74a 100644
--- a/src/config.c
+++ b/src/config.c
@@ -356,18 +356,14 @@ static double parse_leasetime(struct blob_attr *c) {
 	double time = strcmp(val, "infinite") ? strtod(val, &endptr) : UINT32_MAX;
 
 	if (time && endptr && endptr[0]) {
-		if (endptr[0] == 's')
-			time *= 1;
-		else if (endptr[0] == 'm')
-			time *= 60;
-		else if (endptr[0] == 'h')
-			time *= 3600;
-		else if (endptr[0] == 'd')
-			time *= 24 * 3600;
-		else if (endptr[0] == 'w')
-			time *= 7 * 24 * 3600;
-		else
-			goto err;
+		switch(endptr[0]) {
+			case 's': break;
+			case 'm': time *= 60; break;
+			case 'h': time *= 3600; break;
+			case 'd': time *= 24 * 3600; break;
+			case 'w': time *= 7 * 24 * 3600; break;
+			default: goto err;
+		}
 	}
 
 	if (time < 60)
-- 
2.44.0




More information about the openwrt-devel mailing list