From cbdd9e7fed98c7bb49ac2307b3a0651f01baed0c Mon Sep 17 00:00:00 2001 From: Reginald Kennedy Date: Thu, 26 Jul 2012 06:45:40 +0800 Subject: [PATCH] Get actual LOGIN_NAME_MAX value from sysconf. --- spectrwm.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spectrwm.c b/spectrwm.c index 4ded077..0be0227 100644 --- a/spectrwm.c +++ b/spectrwm.c @@ -701,8 +701,8 @@ char * expand_tilde(char *s) { struct passwd *pwd; - int i; - char user[LOGIN_NAME_MAX]; + int i, max; + char *user; const char *sc = s; char *result; @@ -715,6 +715,13 @@ expand_tilde(char *s) } ++s; + + if ((max = sysconf(_SC_LOGIN_NAME_MAX)) == -1) + errx(1, "expand_tilde: sysconf"); + + if ((user = calloc(1, max + 1)) == NULL) + errx(1, "expand_tilde: calloc"); + for (i = 0; s[i] != '/' && s[i] != '\0'; ++i) user[i] = s[i]; user[i] = '\0'; -- 1.7.10.4