While looking at Hubert patch to iri.c (and surrounding code) I noticed that remote_to_utf8 declared the output parameter as const char** (instead of char**) and there was a number casting around to (const char **) and (char *) in the file.

The following patch fixes the prototypes to have sensible values and manages to remove all those casts (I was afraid of still needing one at iconv(3) call).


Sadly, it produces a trivial conflict with Hubert patch due to the rname of the variable 'new':
-      if (!remote_to_utf8 (i, (const char *) host, (const char **) &new))
+      if (!remote_to_utf8 (i, host, &new))
vs
-      if (!remote_to_utf8 (i, (const char *) host, (const char **)&new))
+      if (!remote_to_utf8 (i, (const char *) host, (const char 
**)&utf8_encoded))
with the merge of both being
+      if (!remote_to_utf8 (i, host,&utf8_encoded))

Cheers

>From 795061b3957d115734c625361ef21701bac402c4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=81ngel=20Gonz=C3=A1lez?= <[email protected]>
Date: Mon, 6 Apr 2015 22:14:33 +0200
Subject: [PATCH] Fix const usage in iri.c

* src/iri.c (remote_to_utf8): Do not qualify with const the output pointer.
(do_conversion): Use the provided input parameter as const.
(idn_encode): casts to remote_to_utf8 parameters are no longer needed.
* src/iri.h: Adjusted remote_to_utf8 prototype.
* src/url.c: It is no longer necessary to cast new_url to const char.
---
 src/iri.c | 13 ++++++-------
 src/iri.h |  2 +-
 src/url.c |  2 +-
 3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/iri.c b/src/iri.c
index dc1ebd0..35e5761 100644
--- a/src/iri.c
+++ b/src/iri.c
@@ -117,13 +117,13 @@ check_encoding_name (char *encoding)
    will contain the transcoded string on success. *out content is
    unspecified otherwise. */
 static bool
-do_conversion (const char *tocode, const char *fromcode, char *in, size_t inlen, char **out)
+do_conversion (const char *tocode, const char *fromcode, char const *in_org, size_t inlen, char **out)
 {
   iconv_t cd;
   /* sXXXav : hummm hard to guess... */
   size_t len, done, outlen;
   int invalid = 0, tooshort = 0;
-  char *s, *in_org, *in_save;
+  char *s, *in, *in_save;
 
   cd = iconv_open (tocode, fromcode);
   if (cd == (iconv_t)(-1))
@@ -135,8 +135,7 @@ do_conversion (const char *tocode, const char *fromcode, char *in, size_t inlen,
     }
 
   /* iconv() has to work on an unescaped string */
-  in_org = in;
-  in_save = in = xstrndup(in, inlen);
+  in_save = in = xstrndup(in_org, inlen);
   url_unescape(in);
   inlen = strlen(in);
 
@@ -231,7 +230,7 @@ idn_encode (struct iri *i, char *host)
   /* Encode to UTF-8 if not done */
   if (!i->utf8_encode)
     {
-      if (!remote_to_utf8 (i, (const char *) host, (const char **) &new))
+      if (!remote_to_utf8 (i, host, &new))
           return NULL;  /* Nothing to encode or an error occured */
       host = new;
     }
@@ -271,7 +270,7 @@ idn_decode (char *host)
 /* Try to transcode string str from remote encoding to UTF-8. On success, *new
    contains the transcoded string. *new content is unspecified otherwise. */
 bool
-remote_to_utf8 (struct iri *iri, const char *str, const char **new)
+remote_to_utf8 (struct iri *iri, const char *str, char **new)
 {
   bool ret = false;
 
@@ -293,7 +292,7 @@ remote_to_utf8 (struct iri *iri, const char *str, const char **new)
       return false;
     }
 
-  if (do_conversion ("UTF-8", iri->uri_encoding, (char *) str, strlen (str), (char **) new))
+  if (do_conversion ("UTF-8", iri->uri_encoding, str, strlen (str), new))
     ret = true;
 
   /* Test if something was converted */
diff --git a/src/iri.h b/src/iri.h
index f2ee9c8..8ba50b2 100644
--- a/src/iri.h
+++ b/src/iri.h
@@ -49,7 +49,7 @@ bool check_encoding_name (char *encoding);
 const char *locale_to_utf8 (const char *str);
 char *idn_encode (struct iri *i, char *host);
 char *idn_decode (char *host);
-bool remote_to_utf8 (struct iri *i, const char *str, const char **new);
+bool remote_to_utf8 (struct iri *i, const char *str, char **new);
 struct iri *iri_new (void);
 struct iri *iri_dup (const struct iri *);
 void iri_free (struct iri *i);
diff --git a/src/url.c b/src/url.c
index e3f1e86..e78dbc6 100644
--- a/src/url.c
+++ b/src/url.c
@@ -701,7 +701,7 @@ url_parse (const char *url, int *error, struct iri *iri, bool percent_encode)
     {
       char *new_url = NULL;
 
-      iri->utf8_encode = remote_to_utf8 (iri, iri->orig_url ? iri->orig_url : url, (const char **) &new_url);
+      iri->utf8_encode = remote_to_utf8 (iri, iri->orig_url ? iri->orig_url : url, &new_url);
       if (!iri->utf8_encode)
         new_url = NULL;
       else
-- 
2.3.5

Reply via email to