xC: deal with any identifier conflicts

Invalid UTF-8 converted to UTF-8 may conflict with that
which was valid UTF-8 in the first place.
This commit is contained in:
Přemysl Eric Janouch 2022-08-29 14:40:06 +02:00
parent 313a65180e
commit ef8f25d1dd
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 16 additions and 3 deletions

19
xC.c
View File

@ -4622,11 +4622,24 @@ irc_make_buffer_name (struct server *s, const char *target)
if (!target)
return xstrdup (s->name);
// XXX: this may be able to trigger the uniqueness assertion with non-UTF-8
char *target_utf8 = irc_to_utf8 (target);
char *result = xstrdup_printf ("%s.%s", s->name, target_utf8);
char *name = xstrdup_printf ("%s.%s", s->name, target_utf8);
free (target_utf8);
return result;
struct buffer *conflict = buffer_by_name (s->ctx, name);
if (!conflict)
return name;
hard_assert (conflict->server == s);
// Fix up any conflicts. Note that while parentheses aren't allowed
// in IRC nicknames, they may occur in channel names.
int i = 0;
char *unique = xstrdup_printf ("%s(%d)", name, ++i);
while (buffer_by_name (s->ctx, unique))
cstr_set (&unique, xstrdup_printf ("%s(%d)", name, ++i));
free (name);
return unique;
}
static void