From c57a0512ba5b49534c0c10142998e2aa4172ce01 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Tue, 16 Jul 2024 19:52:47 +0200 Subject: [PATCH] Add assertions Passing an unknown enum value to convert them to string would return NULL without any error, possibly causing undefined behavior later. Add assertions to catch such programming errors early. --- app/src/server.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/server.c b/app/src/server.c index 4d55e994..721c91df 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -147,7 +147,7 @@ log_level_to_server_string(enum sc_log_level level) { return "error"; default: assert(!"unexpected log level"); - return "(unknown)"; + return NULL; } } @@ -183,6 +183,7 @@ sc_server_get_codec_name(enum sc_codec codec) { case SC_CODEC_RAW: return "raw"; default: + assert(!"unexpected codec"); return NULL; } } @@ -197,6 +198,7 @@ sc_server_get_camera_facing_name(enum sc_camera_facing camera_facing) { case SC_CAMERA_FACING_EXTERNAL: return "external"; default: + assert(!"unexpected camera facing"); return NULL; } }