comparison mp_msg.c @ 17931:ed9950b8200d

The fix in mp_msg.c avoids a core dump when iconv_open() fails, the other just makes it possible to compile if USE_ICONV is undefined. Patch by Bjorn Sandell (biorn _At_ chalmers _Dot_ se).
author albeu
date Fri, 24 Mar 2006 02:31:29 +0000
parents 0d7cc103ed1e
children 03170287aea9
comparison
equal deleted inserted replaced
17930:81cbc8debd3c 17931:ed9950b8200d
100 iconv_close(msgiconv); 100 iconv_close(msgiconv);
101 } 101 }
102 msgiconv = iconv_open(mp_msg_charset, MSG_CHARSET); 102 msgiconv = iconv_open(mp_msg_charset, MSG_CHARSET);
103 old_charset = strdup(mp_msg_charset); 103 old_charset = strdup(mp_msg_charset);
104 } 104 }
105 if (msgiconv == (iconv_t)(-1)) {
106 fprintf(stderr,"iconv: conversion from %s to %s unsupported\n"
107 ,mp_msg_charset,MSG_CHARSET);
108 }else{
105 memset(tmp2, 0, MSGSIZE_MAX); 109 memset(tmp2, 0, MSGSIZE_MAX);
106 while (iconv(msgiconv, &in, &inlen, &out, &outlen) == -1) { 110 while (iconv(msgiconv, &in, &inlen, &out, &outlen) == -1) {
107 if (!inlen || !outlen) 111 if (!inlen || !outlen)
108 break; 112 break;
109 *out++ = *in++; 113 *out++ = *in++;
110 outlen--; inlen--; 114 outlen--; inlen--;
111 } 115 }
112 strncpy(tmp, tmp2, MSGSIZE_MAX); 116 strncpy(tmp, tmp2, MSGSIZE_MAX);
113 tmp[MSGSIZE_MAX-1] = 0; 117 tmp[MSGSIZE_MAX-1] = 0;
114 tmp[MSGSIZE_MAX-2] = '\n'; 118 tmp[MSGSIZE_MAX-2] = '\n';
119 }
115 } 120 }
116 #endif 121 #endif
117 122
118 #ifdef MSG_USE_COLORS 123 #ifdef MSG_USE_COLORS
119 /* that's only a silly color test */ 124 /* that's only a silly color test */