client: handle UID rollover. ircd-ratbox r28917

This commit is contained in:
William Pitcock 2016-03-02 15:56:49 -06:00
parent 65f2c0a263
commit 428f9bc117

View file

@ -1860,19 +1860,21 @@ init_uid(void)
char *
generate_uid(void)
{
static int flipped = 0;
int i;
uid_restart:
for(i = 8; i > 3; i--)
{
if(current_uid[i] == 'Z')
{
current_uid[i] = '0';
return current_uid;
goto out;
}
else if(current_uid[i] != '9')
{
current_uid[i]++;
return current_uid;
goto out;
}
else
current_uid[i] = 'A';
@ -1882,11 +1884,18 @@ generate_uid(void)
if(current_uid[3] == 'Z')
{
current_uid[i] = 'A';
s_assert(0);
flipped = 1;
}
else
current_uid[i]++;
out:
/* if this happens..well, i'm not sure what to say, but lets handle it correctly */
if(rb_unlikely(flipped))
{
/* this slows down uid generation a bit... */
if(find_id(current_uid) != NULL)
goto uid_restart;
}
return current_uid;
}