From 443cb14d6e8c37cb6f633bfd486ff669af9d4121 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 18 Nov 2021 18:48:11 +0100 Subject: [PATCH] Assume non-NULL serial in file_handler The previous commit guarantees to always initialize the serial, so the file_handle may assume it is never NULL. --- app/src/file_handler.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/app/src/file_handler.c b/app/src/file_handler.c index fe0ab857..b067d2f1 100644 --- a/app/src/file_handler.c +++ b/app/src/file_handler.c @@ -16,6 +16,7 @@ file_handler_request_destroy(struct file_handler_request *req) { bool file_handler_init(struct file_handler *file_handler, const char *serial, const char *push_target) { + assert(serial); cbuf_init(&file_handler->queue); @@ -30,16 +31,12 @@ file_handler_init(struct file_handler *file_handler, const char *serial, return false; } - if (serial) { - file_handler->serial = strdup(serial); - if (!file_handler->serial) { - LOGW("Could not strdup serial"); - sc_cond_destroy(&file_handler->event_cond); - sc_mutex_destroy(&file_handler->mutex); - return false; - } - } else { - file_handler->serial = NULL; + file_handler->serial = strdup(serial); + if (!file_handler->serial) { + LOGE("Could not strdup serial"); + sc_cond_destroy(&file_handler->event_cond); + sc_mutex_destroy(&file_handler->mutex); + return false; } // lazy initialization