aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-08-29 14:40:06 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-08-29 14:41:23 +0200
commitef8f25d1dd8905e56f8f20adf0bda4ecd4e19e40 (patch)
treed233a7b5e561c6129cc7cd6fdf64df164ea759d6
parent313a65180e13215711aa30e5c009065e5050065f (diff)
downloadxK-ef8f25d1dd8905e56f8f20adf0bda4ecd4e19e40.tar.gz
xK-ef8f25d1dd8905e56f8f20adf0bda4ecd4e19e40.tar.xz
xK-ef8f25d1dd8905e56f8f20adf0bda4ecd4e19e40.zip
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.
-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