From 4a25f5462fc76f89d3b9338ca2eaf84397e634c3 Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Wed, 14 Aug 2013 09:32:33 +0000 Subject: [PATCH] Simplify code that produces realname from gecos, replace strmcat() with strlcat(). git-svn-id: svn://svn.code.sf.net/p/bitchx/code/trunk@319 13b04d17-f746-0410-82c6-800466cd88b0 --- source/irc.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/source/irc.c b/source/irc.c index 6f8f178..60598a9 100644 --- a/source/irc.c +++ b/source/irc.c @@ -1063,23 +1063,28 @@ static char *parse_args (char *argv[], int argc, char **envp) { #ifdef GECOS_DELIMITER if ((ptr = strchr(entry->pw_gecos, GECOS_DELIMITER))) - *ptr = (char) 0; + *ptr = 0; #endif - if ((ptr = strchr(entry->pw_gecos, '&')) == NULL) - strlcpy(realname, entry->pw_gecos, sizeof realname); - else { - int len = ptr - entry->pw_gecos; + /* The first '&' character in pw_gecos is replaced with pw_name */ + if ((ptr = strchr(entry->pw_gecos, '&'))) + *ptr = 0; - if (len < REALNAME_LEN && *(entry->pw_name)) { - char *q = realname + len; + strlcpy(realname, entry->pw_gecos, sizeof realname); - strlcpy(realname, entry->pw_gecos, len); - strmcat(realname, entry->pw_name, REALNAME_LEN); - strmcat(realname, ptr + 1, REALNAME_LEN); - if (islower((unsigned char)*q) && (q == realname || isspace((unsigned char)*(q - 1)))) - *q = toupper(*q); - } else - strlcpy(realname, entry->pw_gecos, sizeof realname); + if (ptr) + { + size_t len = ptr - entry->pw_gecos; + + strlcat(realname, entry->pw_name, sizeof realname); + strlcat(realname, ptr + 1, sizeof realname); + + /* Make the first character of the username uppercase, if + it's preceeded by a space */ + if (len < sizeof realname && *(entry->pw_name) && + (len == 0 || isspace((unsigned char)realname[len - 1]))) + { + realname[len] = toupper((unsigned char)realname[len]); + } } } if (entry->pw_name && *(entry->pw_name) && !*username)