mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-09 11:00:50 +00:00
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>
This commit is contained in:
parent
c0dc23460b
commit
bd1058c0af
@ -121,6 +121,7 @@ int zlog_filter_del(const char *filter)
|
|||||||
pthread_mutex_lock(&loglock);
|
pthread_mutex_lock(&loglock);
|
||||||
|
|
||||||
int found_idx = zlog_filter_lookup(filter);
|
int found_idx = zlog_filter_lookup(filter);
|
||||||
|
int last_idx = zlog_filter_count - 1;
|
||||||
|
|
||||||
if (found_idx == -1) {
|
if (found_idx == -1) {
|
||||||
/* Didn't find the filter to delete */
|
/* Didn't find the filter to delete */
|
||||||
@ -128,10 +129,9 @@ int zlog_filter_del(const char *filter)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Remove and adjust the filter array */
|
/* Adjust the filter array */
|
||||||
for (int i = found_idx; i < zlog_filter_count - 1; i++)
|
memmove(zlog_filters[found_idx], zlog_filters[found_idx + 1],
|
||||||
strlcpy(zlog_filters[i], zlog_filters[i + 1],
|
(last_idx - found_idx) * sizeof(zlog_filters[0]));
|
||||||
sizeof(zlog_filters[0]));
|
|
||||||
|
|
||||||
zlog_filter_count--;
|
zlog_filter_count--;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user