]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: Use memmove to adjust filters after del
authorStephen Worley <sworley@cumulusnetworks.com>
Tue, 18 Jun 2019 23:22:03 +0000 (19:22 -0400)
committerStephen Worley <sworley@cumulusnetworks.com>
Wed, 19 Jun 2019 21:20:24 +0000 (17:20 -0400)
Simplify the code in deleting a filter by using memmove rather
than iterating. Memmove handles overlapping strings safely so
this is fine here.

Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
lib/log.c

index 80ca66ca8d977da49adced8d765647346fe7b001..4b8c55d65d602ac742ce274618aa08e1270ac45c 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -121,6 +121,7 @@ int zlog_filter_del(const char *filter)
        pthread_mutex_lock(&loglock);
 
        int found_idx = zlog_filter_lookup(filter);
+       int last_idx = zlog_filter_count - 1;
 
        if (found_idx == -1) {
                /* Didn't find the filter to delete */
@@ -128,10 +129,9 @@ int zlog_filter_del(const char *filter)
                return -1;
        }
 
-       /* Remove and adjust the filter array */
-       for (int i = found_idx; i < zlog_filter_count - 1; i++)
-               strlcpy(zlog_filters[i], zlog_filters[i + 1],
-                       sizeof(zlog_filters[0]));
+       /* Adjust the filter array */
+       memmove(zlog_filters[found_idx], zlog_filters[found_idx + 1],
+               (last_idx - found_idx) * sizeof(zlog_filters[0]));
 
        zlog_filter_count--;