return good pointer and free good pointer

This commit is contained in:
Julien Danjou 2008-02-11 09:21:09 +01:00
parent fbce780003
commit 321a481dce
1 changed files with 11 additions and 4 deletions

View File

@ -43,7 +43,7 @@ draw_iso2utf8(char *iso)
return NULL; return NULL;
if(!a_strcmp(nl_langinfo(CODESET), "UTF-8")) if(!a_strcmp(nl_langinfo(CODESET), "UTF-8"))
return iso; return NULL;
iso2utf8 = iconv_open("UTF-8", nl_langinfo(CODESET)); iso2utf8 = iconv_open("UTF-8", nl_langinfo(CODESET));
if(iso2utf8 == (iconv_t) -1) if(iso2utf8 == (iconv_t) -1)
@ -63,6 +63,7 @@ draw_iso2utf8(char *iso)
if(iconv(iso2utf8, &iso, &len, &utf8, &utf8len) == (size_t) -1) if(iconv(iso2utf8, &iso, &len, &utf8, &utf8len) == (size_t) -1)
{ {
perror("awesome: text conversion failed"); perror("awesome: text conversion failed");
p_delete(&utf8);
return NULL; return NULL;
} }
@ -126,7 +127,7 @@ draw_text(DrawCtx *ctx,
{ {
int nw = 0; int nw = 0;
ssize_t len, olen; ssize_t len, olen;
char *buf; char *buf, *utf8;
cairo_font_face_t *font_face; cairo_font_face_t *font_face;
draw_rectangle(ctx, area, True, bg); draw_rectangle(ctx, area, True, bg);
@ -136,9 +137,15 @@ draw_text(DrawCtx *ctx,
/* copy text to buffer */ /* copy text to buffer */
buf = a_strdup(text); buf = a_strdup(text);
/* try to convert it to UTF-8 */ /* try to convert it to UTF-8 */
if(!(buf = draw_iso2utf8(buf))) if((utf8 = draw_iso2utf8(buf)))
return; {
/* conversion success */
p_delete(&buf);
buf = utf8;
len = olen = a_strlen(buf);
}
/* check that the text is not too long */ /* check that the text is not too long */
while(len && (nw = (draw_textwidth(ctx->display, font, buf)) + padding * 2) > area.width) while(len && (nw = (draw_textwidth(ctx->display, font, buf)) + padding * 2) > area.width)