[glib: 3/8] guri: Refactor error handling in parse_ip_literal()




commit 7e400a886e4dd809f002941acb43ff3ba870b6aa
Author: Philip Withnall <pwithnall endlessos org>
Date:   Wed Sep 30 17:50:38 2020 +0100

    guri: Refactor error handling in parse_ip_literal()
    
    Having the goto labels at the bottom of a function makes things a little
    more readable. This introduces no functional changes.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 glib/guri.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/glib/guri.c b/glib/guri.c
index 6c5e579cb..056b86a2e 100644
--- a/glib/guri.c
+++ b/glib/guri.c
@@ -466,14 +466,7 @@ parse_ip_literal (const gchar  *start,
   gchar *addr = NULL;
 
   if (start[length - 1] != ']')
-    {
-    bad_ipv6_literal:
-      g_free (addr);
-      g_set_error (error, G_URI_ERROR, G_URI_ERROR_BAD_HOST,
-                   _("Invalid IPv6 address ā€˜%.*sā€™ in URI"),
-                   (gint)length, start);
-      return FALSE;
-    }
+    goto bad_ipv6_literal;
 
   addr = g_strndup (start + 1, length - 2);
 
@@ -499,9 +492,18 @@ parse_ip_literal (const gchar  *start,
   /* Success */
   if (out != NULL)
     *out = g_steal_pointer (&addr);
+
   g_free (addr);
 
   return TRUE;
+
+bad_ipv6_literal:
+  g_free (addr);
+  g_set_error (error, G_URI_ERROR, G_URI_ERROR_BAD_HOST,
+               _("Invalid IPv6 address ā€˜%.*sā€™ in URI"),
+               (gint)length, start);
+
+  return FALSE;
 }
 
 static gboolean


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