X-Git-Url: https://git.tokkee.org/?p=tig.git;a=blobdiff_plain;f=tig.c;h=b0032ea67a9fd869b658fa3e984c38007a6250d6;hp=d33d3eb528c8920328cb4b4e87d9b1fe6a9119a7;hb=HEAD;hpb=0cd8f8485547a641873db71319da97ddc123b197 diff --git a/tig.c b/tig.c index d33d3eb..b0032ea 100644 --- a/tig.c +++ b/tig.c @@ -158,19 +158,27 @@ get_author_initials(const char *author) unsigned char bytes; size_t i; - while (is_initial_sep(*author)) + while (author < end && is_initial_sep(*author)) author++; bytes = utf8_char_length(author, end); - if (bytes < sizeof(initials) - 1 - pos) { - while (bytes--) { - initials[pos++] = *author++; - } + if (bytes >= sizeof(initials) - 1 - pos) + break; + while (bytes--) { + initials[pos++] = *author++; } - for (i = pos; author < end && !is_initial_sep(*author); author++) { - if (i < sizeof(initials) - 1) - initials[i++] = *author; + i = pos; + while (author < end && !is_initial_sep(*author)) { + bytes = utf8_char_length(author, end); + if (bytes >= sizeof(initials) - 1 - i) { + while (author < end && !is_initial_sep(*author)) + author++; + break; + } + while (bytes--) { + initials[i++] = *author++; + } } initials[i++] = 0;