- /* Copy the actual text to our i3String */
- str->utf8 = scalloc(num_bytes + 1, 1);
- strncpy(str->utf8, from_utf8, num_bytes);
- str->utf8[num_bytes] = '\0';
+ /* g_utf8_make_valid NULL-terminates the string. */
+ str->utf8 = g_utf8_make_valid(from_utf8, num_bytes);