about summary refs log tree commit
path: root/ext/rpatricia/patricia.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/rpatricia/patricia.c')
-rw-r--r--ext/rpatricia/patricia.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ext/rpatricia/patricia.c b/ext/rpatricia/patricia.c
index 94d8465..cf25167 100644
--- a/ext/rpatricia/patricia.c
+++ b/ext/rpatricia/patricia.c
@@ -170,12 +170,14 @@ ascii2prefix(char *string, prefix_t *prefix)
     slash = memchr(string, '/', len);
     if (slash) {
         bitlen = strtol(slash + 1, &end, 10);
-        if (*end || (bitlen < 0) || ((slash - string) >= (int)sizeof(save)))
+        len = slash - string;
+
+        if (*end || (bitlen < 0) || len >= sizeof(save))
             return NULL;
 
         /* copy the string to save. Avoid destroying the string */
-        memcpy(save, string, slash - string);
-        save[slash - string] = '\0';
+        memcpy(save, string, len);
+        save[len] = '\0';
         string = save;
     } else {
         bitlen = -1;