summaryrefslogtreecommitdiff
path: root/lib/log.c
diff options
context:
space:
mode:
authorStephen Worley <sworley@cumulusnetworks.com>2019-06-18 19:22:03 -0400
committerStephen Worley <sworley@cumulusnetworks.com>2019-06-19 17:20:24 -0400
commitbd1058c0af41dc68aa6b2b3ac72e073eff0bb8f2 (patch)
treee566f3d5ae998fc91671b7ebcc047be36a01dfd4 /lib/log.c
parentc0dc23460ba43192703a3bf76eca08c71257d42c (diff)
lib: Use memmove to adjust filters after del
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>
Diffstat (limited to 'lib/log.c')
-rw-r--r--lib/log.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/log.c b/lib/log.c
index 80ca66ca8d..4b8c55d65d 100644
--- 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--;