On Wednesday 16 December 2015 12:25:10 Eli Zaretskii wrote: > > From: Giuseppe Scrivano <[email protected]> > > Cc: [email protected], [email protected] > > Date: Wed, 16 Dec 2015 10:53:51 +0100 > > > > > + for (;;) > > > + { > > > + if (iconv (cd, &fname, &inlen, &s, &outlen) != (size_t)(-1)) > > > + { > > > + /* Flush the last bytes. */ > > > + iconv (cd, NULL, NULL, &s, &outlen); > > > > should not the return code be checked here? > > We should probably simply copy what iri.c does in a similar function, > yes. > > > > + else if (errno == E2BIG) /* Output buffer full */ > > > + { > > > + char *new; > > > + > > > + done = len; > > > + outlen = done + inlen * 2; > > > + new = xmalloc (outlen + 1); > > > + memcpy (new, converted_fname, done); > > > + xfree (converted_fname); > > > > What would be the extra cost in terms of copied bytes if we just replace > > the three lines above with xrealloc? > > I don't know, probably nothing. This is simply copied (with trivial > changes) from do_conversion in iri.c, so if we want to make that > change, we should do it there as well.
Here is the patch for do_conversion in iri.c. @Giuseppe: If it's ok for you, I'll push it. @Eli: If my change is ok for Giuseppe, please apply the changes from iri.c to your patch. If possible, make a local commit and create the attachment/patch with 'git format -1' (or -2 for the latest two commits). That makes it easier for us to apply the patch since author (you) and commit message are copied as well. Regards, Tim
>From bd9101ab98cd0c67ef1ec519ca18175dcdd138bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20R=C3=BChsen?= <[email protected]> Date: Thu, 17 Dec 2015 17:41:32 +0100 Subject: [PATCH] Cleanup code * src/iri.c (do_conversion): Code cleanup --- src/iri.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/iri.c b/src/iri.c index 6c6e8d3..354bfd9 100644 --- a/src/iri.c +++ b/src/iri.c @@ -180,16 +180,10 @@ do_conversion (const char *tocode, const char *fromcode, char const *in_org, siz } else if (errno == E2BIG) /* Output buffer full */ { - char *new; - tooshort++; done = len; - outlen = done + inlen * 2; - new = xmalloc (outlen + 1); - memcpy (new, s, done); - xfree (s); - s = new; - len = outlen; + len = outlen = done + inlen * 2; + s = xrealloc(s, outlen + 1); *out = s + done; } else /* Weird, we got an unspecified error */ -- 2.6.4
