add some comments to explain len computing

This commit is contained in:
Julien Danjou 2007-11-26 09:52:55 +01:00
parent 359ff93666
commit 1722520a2a
1 changed files with 3 additions and 1 deletions

View File

@ -37,7 +37,9 @@ get_client_addr(const char *display)
addr = p_new(struct sockaddr_un, 1);
homedir = getenv("HOME");
path_len = a_strlen(homedir) + a_strlen(CONTROL_UNIX_SOCKET_PATH) + a_strlen(display) + 2;
/* (a_strlen(display) - 1) because we strcat on display + 1 and
* + 3 for /, \0 and possibly 0 if display is NULL */
path_len = a_strlen(homedir) + a_strlen(CONTROL_UNIX_SOCKET_PATH) + (a_strlen(display) - 1) + 3;
if(path_len >= ssizeof(addr->sun_path))
{
fprintf(stderr, "error: path of control UNIX domain socket is too long");