- char *endpos = utf_end(u); /* points behind utf string */
- char *utf_ptr = u->text; /* current position in utf text */
- u2 pos = 0; /* position in c-string */
+ char *endpos; /* points behind utf string */
+ char *utf_ptr; /* current position in utf text */
+ u2 pos = 0; /* position in c-string */
+
+ if (!u) {
+ memcpy(buffer, "NULL", 5); /* 4 chars + terminating \0 */
+ return;
+ }
+
+ endpos = utf_end(u);
+ utf_ptr = u->text;