grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] json: Get rid of casts for `jsmntok_t`


From: Patrick Steinhardt
Subject: [PATCH 2/2] json: Get rid of casts for `jsmntok_t`
Date: Thu, 16 Apr 2020 12:20:15 +0200

With the upstream change having landed that adds a name to the
previously anonymous `jsmntok` typedef, we can now add a forward
declaration for that struct in our code. As a result, we no longer have
to store the `tokens` member of `struct grub_json` as a void pointer but
can instead use the forward declaration, allowing us to get rid of casts
of that field.

Signed-off-by: Patrick Steinhardt <address@hidden>
---
 grub-core/lib/json/json.c | 8 ++++----
 grub-core/lib/json/json.h | 4 +++-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/grub-core/lib/json/json.c b/grub-core/lib/json/json.c
index 15c0d9949..694af4f3a 100644
--- a/grub-core/lib/json/json.c
+++ b/grub-core/lib/json/json.c
@@ -95,7 +95,7 @@ grub_json_getsize (grub_size_t *out, const grub_json_t *json)
 {
   int size;
 
-  size = ((jsmntok_t *)json->tokens)[json->idx].size;
+  size = json->tokens[json->idx].size;
   if (size < 0)
     return GRUB_ERR_OUT_OF_RANGE;
 
@@ -106,7 +106,7 @@ grub_json_getsize (grub_size_t *out, const grub_json_t 
*json)
 grub_err_t
 grub_json_gettype (grub_json_type_t *out, const grub_json_t *json)
 {
-  switch (((jsmntok_t *)json->tokens)[json->idx].type)
+  switch (json->tokens[json->idx].type)
     {
     case JSMN_OBJECT:
       *out = GRUB_JSON_OBJECT;
@@ -142,7 +142,7 @@ grub_json_getchild (grub_json_t *out, const grub_json_t 
*parent, grub_size_t n)
    * array), as well. We thus add the children's size to n on
    * each iteration.
    */
-  p = &((jsmntok_t *)parent->tokens)[parent->idx];
+  p = &parent->tokens[parent->idx];
   while (n--)
     n += p[offset++].size;
 
@@ -197,7 +197,7 @@ get_value (grub_json_type_t *out_type, const char 
**out_string, const grub_json_
       p = &child;
     }
 
-  tok = &((jsmntok_t *) p->tokens)[p->idx];
+  tok = &p->tokens[p->idx];
   p->string[tok->end] = '\0';
 
   *out_string = p->string + tok->start;
diff --git a/grub-core/lib/json/json.h b/grub-core/lib/json/json.h
index 358e4bca3..d9f99454d 100644
--- a/grub-core/lib/json/json.h
+++ b/grub-core/lib/json/json.h
@@ -36,9 +36,11 @@ enum grub_json_type
 };
 typedef enum grub_json_type grub_json_type_t;
 
+typedef struct jsmntok jsmntok_t;
+
 struct grub_json
 {
-  void       *tokens;
+  jsmntok_t   *tokens;
   char       *string;
   grub_size_t idx;
 };
-- 
2.26.1

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]