diff mbox series

[v2,09/10] parser: print warning in case of type mismatch in sw-description

Message ID 20240712152639.4685-1-ceggers@arri.de
State Accepted
Headers show
Series parser: fix various data type problems | expand

Commit Message

Christian Eggers July 12, 2024, 3:26 p.m. UTC
Print a warning if a value in sw-description doesn't match the expected
type. No assignment will happen in this case.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 corelib/parsing_library_libconfig.c |  9 ++++++---
 corelib/parsing_library_libjson.c   | 11 +++++++----
 2 files changed, 13 insertions(+), 7 deletions(-)
diff mbox series

Patch

diff --git a/corelib/parsing_library_libconfig.c b/corelib/parsing_library_libconfig.c
index 4442cefd3c07..e99fbe9dfe9a 100644
--- a/corelib/parsing_library_libconfig.c
+++ b/corelib/parsing_library_libconfig.c
@@ -17,6 +17,7 @@ 
 #include "generated/autoconf.h"
 #include "bsdqueue.h"
 #include "util.h"
+#include "parsers.h"
 #include "parselib.h"
 #include "parselib-private.h"
 
@@ -37,11 +38,13 @@  static unsigned int map_field_type(field_type_t type)
 }
 
 
-static void get_value_libconfig(const config_setting_t *e, void *dest, field_type_t expected_type)
+static void get_value_libconfig(const config_setting_t *e, const char *path, void *dest, field_type_t expected_type)
 {
 	int parsed_type = config_setting_type(e);
-	if (parsed_type != map_field_type(expected_type))
+	if (parsed_type != map_field_type(expected_type)) {
+		WARN("Type mismatch for %s field \"%s\"", SW_DESCRIPTION_FILENAME, path);
 		return;
+	}
 	switch (expected_type) {
 	case TYPE_INT:
 		*(int *)dest = config_setting_get_int(e);
@@ -120,7 +123,7 @@  void get_field_cfg(config_setting_t *e, const char *path, void *dest, field_type
 	if (!elem)
 		return;
 
-	get_value_libconfig(elem, dest, type);
+	get_value_libconfig(elem, path, dest, type);
 }
 
 const char *get_field_string_libconfig(config_setting_t *e, const char *path)
diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c
index 74db22fc63f1..9635ac2a0c2d 100644
--- a/corelib/parsing_library_libjson.c
+++ b/corelib/parsing_library_libjson.c
@@ -17,6 +17,7 @@ 
 #include "generated/autoconf.h"
 #include "bsdqueue.h"
 #include "util.h"
+#include "parsers.h"
 #include "parselib.h"
 #include "parselib-private.h"
 
@@ -118,12 +119,14 @@  const char *get_field_string_json(json_object *e, const char *path)
 	return NULL;
 }
 
-static void get_value_json(json_object *e, void *dest, field_type_t expected_type)
+static void get_value_json(json_object *e, const char *path, void *dest, field_type_t expected_type)
 {
 	enum json_type parsed_type;
 	parsed_type = json_object_get_type(e);
-	if (parsed_type != map_field_type(expected_type))
+	if (parsed_type != map_field_type(expected_type)) {
+		WARN("Type mismatch for %s field \"%s\"", SW_DESCRIPTION_FILENAME, path);
 		return;
+	}
 	switch (expected_type) {
 	case TYPE_BOOL:
 		*(bool *)dest = json_object_get_boolean(e);
@@ -164,9 +167,9 @@  void get_field_json(json_object *e, const char *path, void *dest, field_type_t t
 
 	if (path) {
 		if (json_object_object_get_ex(e, path, &fld))
-			get_value_json(fld, dest, type);
+			get_value_json(fld, path, dest, type);
 	} else {
-		get_value_json(e, dest, type);
+		get_value_json(e, path, dest, type);
 	}
 }