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:
		
							
								
								
									
										19
									
								
								xC.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user