]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Possible fix for bug #1841109: report an error if iconv fails to convert the string
authorFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 11 Jan 2010 08:37:08 +0000 (08:37 +0000)
committerFrédéric Marchal <fmarchal@users.sourceforge.net>
Mon, 11 Jan 2010 08:37:08 +0000 (08:37 +0000)
grepday.c

index d5d8bdeacdbbcc86fdadcbb09caa47699f5b28e4..736cb219542dac2abbbfd52362649cd8cab4f224 100644 (file)
--- 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);