X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=libi3%2Fucs2_conversion.c;h=b583e32cd6a4f9ba667748d5bd423d994bb595c9;hb=96704b2fc037f2b7906184d8580226a1e2611ae4;hp=99beb36832ab51fd725346934c0514ecd6c89e70;hpb=fb11cc2d149bf49d54e29ee2b7ba0ef1a67bdf11;p=i3%2Fi3 diff --git a/libi3/ucs2_conversion.c b/libi3/ucs2_conversion.c index 99beb368..b583e32c 100644 --- a/libi3/ucs2_conversion.c +++ b/libi3/ucs2_conversion.c @@ -2,7 +2,7 @@ * vim:ts=4:sw=4:expandtab * * i3 - an improved dynamic tiling window manager - * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE) + * © 2009 Michael Stapelberg and contributors (see also: LICENSE) * */ #include @@ -23,8 +23,8 @@ static iconv_t ucs2_conversion_descriptor = (iconv_t)-1; */ char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs) { /* Allocate the output buffer (UTF-8 is at most 4 bytes per glyph) */ - size_t buffer_size = num_glyphs * 4 * sizeof(char) + 1; - char *buffer = scalloc(buffer_size * sizeof(char)); + size_t buffer_size = num_glyphs * 4 + 1; + char *buffer = scalloc(buffer_size, 1); /* We need to use an additional pointer, because iconv() modifies it */ char *output = buffer; @@ -35,16 +35,15 @@ char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs) { utf8_conversion_descriptor = iconv_open("UTF-8", "UCS-2BE"); if (utf8_conversion_descriptor == (iconv_t)-1) err(EXIT_FAILURE, "Error opening the conversion context"); - } - else { + } else { /* Reset the existing conversion descriptor */ iconv(utf8_conversion_descriptor, NULL, NULL, NULL, NULL); } /* Do the conversion */ size_t input_len = num_glyphs * sizeof(xcb_char2b_t); - size_t rc = iconv(utf8_conversion_descriptor, (char**)&text, - &input_len, &output, &output_size); + size_t rc = iconv(utf8_conversion_descriptor, (char **)&text, + &input_len, &output, &output_size); if (rc == (size_t)-1) { perror("Converting to UTF-8 failed"); free(buffer); @@ -61,7 +60,7 @@ char *convert_ucs2_to_utf8(xcb_char2b_t *text, size_t num_glyphs) { * returned. It has to be freed when done. * */ -xcb_char2b_t *convert_utf8_to_ucs2(char *input, int *real_strlen) { +xcb_char2b_t *convert_utf8_to_ucs2(char *input, size_t *real_strlen) { /* Calculate the input buffer size (UTF-8 is strlen-safe) */ size_t input_size = strlen(input); @@ -78,15 +77,14 @@ xcb_char2b_t *convert_utf8_to_ucs2(char *input, int *real_strlen) { ucs2_conversion_descriptor = iconv_open("UCS-2BE", "UTF-8"); if (ucs2_conversion_descriptor == (iconv_t)-1) err(EXIT_FAILURE, "Error opening the conversion context"); - } - else { + } else { /* Reset the existing conversion descriptor */ iconv(ucs2_conversion_descriptor, NULL, NULL, NULL, NULL); } /* Do the conversion */ - size_t rc = iconv(ucs2_conversion_descriptor, (char**)&input, - &input_size, (char**)&output, &output_size); + size_t rc = iconv(ucs2_conversion_descriptor, (char **)&input, + &input_size, (char **)&output, &output_size); if (rc == (size_t)-1) { perror("Converting to UCS-2 failed"); free(buffer);