From 4253c92e5f7e216cf1e1b5b55f70f6f2bd09e755 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Tue, 6 Apr 2010 18:33:10 +0000 Subject: [PATCH] WARN and continue on incomplete multibyte sequence git-svn-id: http://svn.osgeo.org/postgis/trunk@5503 b70326c6-7e19-0410-871a-916f4a2858ee --- loader/shp2pgsql-core.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/loader/shp2pgsql-core.c b/loader/shp2pgsql-core.c index 29a5dcadb..85d8113e5 100644 --- a/loader/shp2pgsql-core.c +++ b/loader/shp2pgsql-core.c @@ -80,6 +80,7 @@ char * utf8(const char *fromcode, char *inputbuf) { iconv_t cd; + char *inbufptr = inputbuf; char *outputptr; char *outputbuf; size_t outbytesleft; @@ -100,8 +101,21 @@ utf8(const char *fromcode, char *inputbuf) memset(outputbuf, 0, outbytesleft); outputptr = outputbuf; - if (-1 == iconv(cd, &inputbuf, &inbytesleft, &outputptr, &outbytesleft)) - return NULL; + if (-1 == iconv(cd, &inbufptr, &inbytesleft, &outputptr, &outbytesleft)) + { + switch (errno) + { + case EINVAL: + fprintf(stderr, "WARNING: Incomplete multibyte sequence in string '%s' discarded\n", inputbuf); + *outputptr = '\0'; + break; + case EILSEQ: + fprintf(stderr, "ERROR: Invalid multibyte sequence '%s' in string '%s'\n", inbufptr, inputbuf); + case E2BIG: /* This would be a programmatic error */ + default: + return NULL; + } + } iconv_close (cd); -- 2.40.0