Fix list management in stdio_set_driver_enabled so drivers can be freely added and removed (#822)

This commit is contained in:
Graham Sanderson 2022-05-11 10:44:41 -05:00 committed by GitHub
parent 04c68c554b
commit 60a6fea534
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -180,20 +180,19 @@ int _write(int handle, char *buffer, int length) {
} }
void stdio_set_driver_enabled(stdio_driver_t *driver, bool enable) { void stdio_set_driver_enabled(stdio_driver_t *driver, bool enable) {
stdio_driver_t *prev = drivers; stdio_driver_t **prev = &drivers;
for (stdio_driver_t *d = drivers; d; d = d->next) { while (*prev) {
if (d == driver) { if (*prev == driver) {
if (!enable) { if (!enable) {
prev->next = d->next; *prev = driver->next;
driver->next = NULL; driver->next = NULL;
} }
return; return;
} }
prev = d; prev = &(*prev)->next;
} }
if (enable) { if (enable) {
if (prev) prev->next = driver; *prev = driver;
else drivers = driver;
} }
} }