diff mbox series

[1/5] util/uri: Remove the unused "target" argument from uri_string_unescape()

Message ID 20240122191753.103118-2-thuth@redhat.com
State New
Headers show
Series util/uri: Simplify the code, remove unused functions | expand

Commit Message

Thomas Huth Jan. 22, 2024, 7:17 p.m. UTC
All callers pass NULL as target, so we can simplify the code by
dropping this parameter.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 include/qemu/uri.h |  2 +-
 util/uri.c         | 32 ++++++++++++++------------------
 2 files changed, 15 insertions(+), 19 deletions(-)

Comments

Philippe Mathieu-Daudé Jan. 23, 2024, 5:45 a.m. UTC | #1
On 22/1/24 20:17, Thomas Huth wrote:
> All callers pass NULL as target, so we can simplify the code by
> dropping this parameter.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   include/qemu/uri.h |  2 +-
>   util/uri.c         | 32 ++++++++++++++------------------
>   2 files changed, 15 insertions(+), 19 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
diff mbox series

Patch

diff --git a/include/qemu/uri.h b/include/qemu/uri.h
index 1855b764f2..aa54b6f251 100644
--- a/include/qemu/uri.h
+++ b/include/qemu/uri.h
@@ -79,7 +79,7 @@  URI *uri_parse_raw(const char *str, int raw);
 int uri_parse_into(URI *uri, const char *str);
 char *uri_to_string(URI *uri);
 char *uri_string_escape(const char *str, const char *list);
-char *uri_string_unescape(const char *str, int len, char *target);
+char *uri_string_unescape(const char *str, int len);
 void uri_free(URI *uri);
 
 /* Single web service query parameter 'name=value'. */
diff --git a/util/uri.c b/util/uri.c
index dcb3305236..33b6c7214e 100644
--- a/util/uri.c
+++ b/util/uri.c
@@ -267,7 +267,7 @@  static int rfc3986_parse_fragment(URI *uri, const char **str)
         if (uri->cleanup & 2) {
             uri->fragment = g_strndup(*str, cur - *str);
         } else {
-            uri->fragment = uri_string_unescape(*str, cur - *str, NULL);
+            uri->fragment = uri_string_unescape(*str, cur - *str);
         }
     }
     *str = cur;
@@ -368,7 +368,7 @@  static int rfc3986_parse_user_info(URI *uri, const char **str)
             if (uri->cleanup & 2) {
                 uri->user = g_strndup(*str, cur - *str);
             } else {
-                uri->user = uri_string_unescape(*str, cur - *str, NULL);
+                uri->user = uri_string_unescape(*str, cur - *str);
             }
         }
         *str = cur;
@@ -496,7 +496,7 @@  found:
             if (uri->cleanup & 2) {
                 uri->server = g_strndup(host, cur - host);
             } else {
-                uri->server = uri_string_unescape(host, cur - host, NULL);
+                uri->server = uri_string_unescape(host, cur - host);
             }
         } else {
             uri->server = NULL;
@@ -614,7 +614,7 @@  static int rfc3986_parse_path_ab_empty(URI *uri, const char **str)
             if (uri->cleanup & 2) {
                 uri->path = g_strndup(*str, cur - *str);
             } else {
-                uri->path = uri_string_unescape(*str, cur - *str, NULL);
+                uri->path = uri_string_unescape(*str, cur - *str);
             }
         } else {
             uri->path = NULL;
@@ -663,7 +663,7 @@  static int rfc3986_parse_path_absolute(URI *uri, const char **str)
             if (uri->cleanup & 2) {
                 uri->path = g_strndup(*str, cur - *str);
             } else {
-                uri->path = uri_string_unescape(*str, cur - *str, NULL);
+                uri->path = uri_string_unescape(*str, cur - *str);
             }
         } else {
             uri->path = NULL;
@@ -709,7 +709,7 @@  static int rfc3986_parse_path_rootless(URI *uri, const char **str)
             if (uri->cleanup & 2) {
                 uri->path = g_strndup(*str, cur - *str);
             } else {
-                uri->path = uri_string_unescape(*str, cur - *str, NULL);
+                uri->path = uri_string_unescape(*str, cur - *str);
             }
         } else {
             uri->path = NULL;
@@ -755,7 +755,7 @@  static int rfc3986_parse_path_no_scheme(URI *uri, const char **str)
             if (uri->cleanup & 2) {
                 uri->path = g_strndup(*str, cur - *str);
             } else {
-                uri->path = uri_string_unescape(*str, cur - *str, NULL);
+                uri->path = uri_string_unescape(*str, cur - *str);
             }
         } else {
             uri->path = NULL;
@@ -1574,7 +1574,6 @@  static int is_hex(char c)
  * uri_string_unescape:
  * @str:  the string to unescape
  * @len:   the length in bytes to unescape (or <= 0 to indicate full string)
- * @target:  optional destination buffer
  *
  * Unescaping routine, but does not check that the string is an URI. The
  * output is a direct unsigned char translation of %XX values (no encoding)
@@ -1584,7 +1583,7 @@  static int is_hex(char c)
  * Returns a copy of the string, but unescaped, will return NULL only in case
  * of error
  */
-char *uri_string_unescape(const char *str, int len, char *target)
+char *uri_string_unescape(const char *str, int len)
 {
     char *ret, *out;
     const char *in;
@@ -1599,11 +1598,8 @@  char *uri_string_unescape(const char *str, int len, char *target)
         return NULL;
     }
 
-    if (target == NULL) {
-        ret = g_malloc(len + 1);
-    } else {
-        ret = target;
-    }
+    ret = g_malloc(len + 1);
+
     in = str;
     out = ret;
     while (len > 0) {
@@ -2274,14 +2270,14 @@  struct QueryParams *query_params_parse(const char *query)
          * and consistent with CGI.pm we assume value is "".
          */
         else if (!eq) {
-            name = uri_string_unescape(query, end - query, NULL);
+            name = uri_string_unescape(query, end - query);
             value = NULL;
         }
         /* Or if we have "name=" here (works around annoying
          * problem when calling uri_string_unescape with len = 0).
          */
         else if (eq + 1 == end) {
-            name = uri_string_unescape(query, eq - query, NULL);
+            name = uri_string_unescape(query, eq - query);
             value = g_new0(char, 1);
         }
         /* If the '=' character is at the beginning then we have
@@ -2293,8 +2289,8 @@  struct QueryParams *query_params_parse(const char *query)
 
         /* Otherwise it's "name=value". */
         else {
-            name = uri_string_unescape(query, eq - query, NULL);
-            value = uri_string_unescape(eq + 1, end - (eq + 1), NULL);
+            name = uri_string_unescape(query, eq - query);
+            value = uri_string_unescape(eq + 1, end - (eq + 1));
         }
 
         /* Append to the parameter set. */