diff mbox series

[v2,01/10] parser: field_type_t::TYPE_STRING: remove

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

Commit Message

Christian Eggers July 12, 2024, 3:22 p.m. UTC
This isn't used anywhere (GET_FIELD_STRING() uses a separate method for
retrieving strings). Get rid of dangerous strcpy() call in json parser.

Signed-off-by: Christian Eggers <ceggers@arri.de>
---
 corelib/parsing_library_libconfig.c | 5 -----
 corelib/parsing_library_libjson.c   | 5 -----
 include/parselib.h                  | 1 -
 3 files changed, 11 deletions(-)

Comments

Stefano Babic July 13, 2024, 8:55 a.m. UTC | #1
On 12.07.24 17:22, Christian Eggers wrote:
> This isn't used anywhere (GET_FIELD_STRING() uses a separate method for
> retrieving strings).

Yes, that's true - this is at the moment dead code, implemented just for
completeness.

> Get rid of dangerous strcpy() call in json parser.
>

We can drop it.

> Signed-off-by: Christian Eggers <ceggers@arri.de>
> ---
>   corelib/parsing_library_libconfig.c | 5 -----
>   corelib/parsing_library_libjson.c   | 5 -----
>   include/parselib.h                  | 1 -
>   3 files changed, 11 deletions(-)
>
> diff --git a/corelib/parsing_library_libconfig.c b/corelib/parsing_library_libconfig.c
> index ddb79f6fb152..a3535e9ec0e4 100644
> --- a/corelib/parsing_library_libconfig.c
> +++ b/corelib/parsing_library_libconfig.c
> @@ -27,8 +27,6 @@ static unsigned int map_field_type(field_type_t type)
>   		return CONFIG_TYPE_INT;
>   	case TYPE_INT64:
>   		return CONFIG_TYPE_INT64;
> -	case TYPE_STRING:
> -		return CONFIG_TYPE_STRING;
>   	case TYPE_BOOL:
>   		return CONFIG_TYPE_BOOL;
>   	case TYPE_FLOAT:
> @@ -51,9 +49,6 @@ static void get_value_libconfig(const config_setting_t *e, void *dest, field_typ
>   	case CONFIG_TYPE_INT64:
>   		*(long long *)dest = config_setting_get_int64(e);
>   		break;
> -	case CONFIG_TYPE_STRING:
> -		dest = (void *)config_setting_get_string(e);
> -		break;
>   	case CONFIG_TYPE_BOOL:
>   		*(bool *)dest = config_setting_get_bool(e);
>   		break;
> diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c
> index 4728d200fc8e..86646676d419 100644
> --- a/corelib/parsing_library_libjson.c
> +++ b/corelib/parsing_library_libjson.c
> @@ -28,8 +28,6 @@ static json_type map_field_type(field_type_t type)
>   	case TYPE_INT:
>   	case TYPE_INT64:
>   		return json_type_int;
> -	case TYPE_STRING:
> -		return json_type_string;
>   	case TYPE_BOOL:
>   		return json_type_boolean;
>   	case TYPE_FLOAT:
> @@ -133,9 +131,6 @@ static void get_value_json(json_object *e, void *dest, field_type_t expected_typ
>   	case json_type_int:
>   		*(unsigned int *)dest = json_object_get_int(e);
>   		break;
> -	case json_type_string:
> -		strcpy(dest, json_object_get_string(e));
> -		break;
>   	case json_type_double:
>   		*(double *)dest = json_object_get_double(e);
>   		break;
> diff --git a/include/parselib.h b/include/parselib.h
> index 99b6519fa480..b0142ff26840 100644
> --- a/include/parselib.h
> +++ b/include/parselib.h
> @@ -27,7 +27,6 @@ typedef enum {
>   typedef enum {
>   	TYPE_INT,
>   	TYPE_INT64,
> -	TYPE_STRING,
>   	TYPE_BOOL,
>   	TYPE_FLOAT
>   } field_type_t;


Acked-by: Stefano Babic <stefano.babic@swupdate.org>
diff mbox series

Patch

diff --git a/corelib/parsing_library_libconfig.c b/corelib/parsing_library_libconfig.c
index ddb79f6fb152..a3535e9ec0e4 100644
--- a/corelib/parsing_library_libconfig.c
+++ b/corelib/parsing_library_libconfig.c
@@ -27,8 +27,6 @@  static unsigned int map_field_type(field_type_t type)
 		return CONFIG_TYPE_INT;
 	case TYPE_INT64:
 		return CONFIG_TYPE_INT64;
-	case TYPE_STRING:
-		return CONFIG_TYPE_STRING;
 	case TYPE_BOOL:
 		return CONFIG_TYPE_BOOL;
 	case TYPE_FLOAT:
@@ -51,9 +49,6 @@  static void get_value_libconfig(const config_setting_t *e, void *dest, field_typ
 	case CONFIG_TYPE_INT64:
 		*(long long *)dest = config_setting_get_int64(e);
 		break;
-	case CONFIG_TYPE_STRING:
-		dest = (void *)config_setting_get_string(e);
-		break;
 	case CONFIG_TYPE_BOOL:
 		*(bool *)dest = config_setting_get_bool(e);
 		break;
diff --git a/corelib/parsing_library_libjson.c b/corelib/parsing_library_libjson.c
index 4728d200fc8e..86646676d419 100644
--- a/corelib/parsing_library_libjson.c
+++ b/corelib/parsing_library_libjson.c
@@ -28,8 +28,6 @@  static json_type map_field_type(field_type_t type)
 	case TYPE_INT:
 	case TYPE_INT64:
 		return json_type_int;
-	case TYPE_STRING:
-		return json_type_string;
 	case TYPE_BOOL:
 		return json_type_boolean;
 	case TYPE_FLOAT:
@@ -133,9 +131,6 @@  static void get_value_json(json_object *e, void *dest, field_type_t expected_typ
 	case json_type_int:
 		*(unsigned int *)dest = json_object_get_int(e);
 		break;
-	case json_type_string:
-		strcpy(dest, json_object_get_string(e));
-		break;
 	case json_type_double:
 		*(double *)dest = json_object_get_double(e);
 		break;
diff --git a/include/parselib.h b/include/parselib.h
index 99b6519fa480..b0142ff26840 100644
--- a/include/parselib.h
+++ b/include/parselib.h
@@ -27,7 +27,6 @@  typedef enum {
 typedef enum {
 	TYPE_INT,
 	TYPE_INT64,
-	TYPE_STRING,
 	TYPE_BOOL,
 	TYPE_FLOAT
 } field_type_t;