From 97a2f8f42ee0da71060de7f20beb3832f1d5059c Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Sun, 27 Aug 2023 22:57:58 -0300 Subject: [PATCH] Apply a small optimization to iscidraddr.c --- src/iscidraddr.c | 3 ++- test/iscidraddr_test.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/iscidraddr.c b/src/iscidraddr.c index 1ce8f93..ccd01ae 100644 --- a/src/iscidraddr.c +++ b/src/iscidraddr.c @@ -9,11 +9,12 @@ int iscidraddr(const char *str) { size_t offset = 0; - size_t len = (str == NULL ? 0 : strnlen(str, 20)); + size_t len = (str == NULL ? 0 : strnlen(str, 16)); for(size_t i = 0; i < len; i++) { if(str[i] == '/') { offset = i; + break; } } if (offset == 0) { diff --git a/test/iscidraddr_test.c b/test/iscidraddr_test.c index 6a888b6..95440fb 100644 --- a/test/iscidraddr_test.c +++ b/test/iscidraddr_test.c @@ -11,6 +11,7 @@ const char *valid[] = { /* valid cidr notation */ "10.0.0.1/8", "10.0.0.1/16", "10.0.0.1/24", "10.0.0.1/32", + "255.255.255.255/32" }; const char *invalid[] = {