summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--xC.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/xC.c b/xC.c
index 9664cb7..5b8dda2 100644
--- a/xC.c
+++ b/xC.c
@@ -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