From 077095486efde6d1a7f2ad3beca8282d7788f54b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20Marchal?= Date: Mon, 11 Jan 2010 08:37:08 +0000 Subject: [PATCH] Possible fix for bug #1841109: report an error if iconv fails to convert the string --- grepday.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/grepday.c b/grepday.c index d5d8bde..736cb21 100644 --- a/grepday.c +++ b/grepday.c @@ -64,8 +64,17 @@ static char * I18NgdImageStringFT (gdImage * im, int *brect, int fg, char *fontl sstr = (char *) sstring; localtoutf = iconv_open ("UTF-8", CharSet); - iconv (localtoutf, (ICONV_CONST char **)&str, &slen, &sstr, &sslen); - iconv_close (localtoutf); + if (localtoutf==(iconv_t)-1) { + fprintf(stderr,"SARG(grepday) iconv cannot convert from %s to UTF-8 - %s\n",CharSet,strerror(errno)); + strcpy(sstring,string); //show something sensible on the graph + } + else { + if (iconv (localtoutf, (ICONV_CONST char **)&str, &slen, &sstr, &sslen)==-1) { + fprintf(stderr,"SARG(grepday) iconv failed to convert string \"%s\" from %s to UTF-8 - %s\n",string,CharSet,strerror(errno)); + strcpy(sstring,string); //show something sensible on the graph + } + iconv_close (localtoutf); + } retval = gdImageStringFTEx (im, brect, fg, fontlist, ptsize, angle, x, y, sstring, gdFTEX_Unicode); free(sstring); -- 2.47.2