From b39c18596d05cea1b3c0f0445b17080e9a2e4c19 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Sat, 23 Jan 2010 00:37:21 +0100 Subject: * apt-pkg/contrib/fileutl.cc: - Fix the newly introduced method GetListOfFilesInDir to not accept every file if no extension is enforced (= restore old behaviour). (Closes: #565213) * apt-pkg/policy.cc: - accept also partfiles with "pref" file extension as valid * apt-pkg/contrib/configuration.cc: - accept also partfiles with "conf" file extension as valid * doc/apt.conf.5.xml: - reorder description and split out syntax - add partfile name convention (Closes: #558348) * doc/apt_preferences.conf.5.xml: - describe partfile name convention also here * apt-pkg/deb/dpkgpm.cc: - don't segfault if term.log file can't be opened. Thanks Sam Brightman for the patch! (Closes: #475770) * doc/*: - replace the per language addendum with a global addendum - add a explanation why translations include (maybe) english parts to the new global addendum (Closes: #561636) * apt-pkg/contrib/strutl.cc: - fix malloc asseration fail with ja_JP.eucJP locale in apt-cache search. Thanks Kusanagi Kouichi! (Closes: #548884) --- apt-pkg/contrib/strutl.cc | 49 +++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'apt-pkg/contrib/strutl.cc') diff --git a/apt-pkg/contrib/strutl.cc b/apt-pkg/contrib/strutl.cc index 4c05f2df8..2913fbf44 100644 --- a/apt-pkg/contrib/strutl.cc +++ b/apt-pkg/contrib/strutl.cc @@ -43,9 +43,10 @@ bool UTF8ToCodeset(const char *codeset, const string &orig, string *dest) { iconv_t cd; const char *inbuf; - char *inptr, *outbuf, *outptr; - size_t insize, outsize; - + char *inptr, *outbuf; + size_t insize, bufsize; + dest->clear(); + cd = iconv_open(codeset, "UTF-8"); if (cd == (iconv_t)(-1)) { // Something went wrong @@ -55,33 +56,49 @@ bool UTF8ToCodeset(const char *codeset, const string &orig, string *dest) else perror("iconv_open"); - // Clean the destination string - *dest = ""; - return false; } - insize = outsize = orig.size(); + insize = bufsize = orig.size(); inbuf = orig.data(); inptr = (char *)inbuf; - outbuf = new char[insize+1]; - outptr = outbuf; + outbuf = new char[bufsize]; + size_t lastError = -1; while (insize != 0) { + char *outptr = outbuf; + size_t outsize = bufsize; size_t const err = iconv(cd, &inptr, &insize, &outptr, &outsize); + dest->append(outbuf, outptr - outbuf); if (err == (size_t)(-1)) { - insize--; - outsize++; - inptr++; - *outptr = '?'; - outptr++; + switch (errno) + { + case EILSEQ: + insize--; + inptr++; + // replace a series of unknown multibytes with a single "?" + if (lastError != insize) { + lastError = insize - 1; + dest->append("?"); + } + break; + case EINVAL: + insize = 0; + break; + case E2BIG: + if (outptr == outbuf) + { + bufsize *= 2; + delete[] outbuf; + outbuf = new char[bufsize]; + } + break; + } } } - *outptr = '\0'; - *dest = outbuf; delete[] outbuf; iconv_close(cd); -- cgit v1.2.3