The patch replaces the use of macro PATH_MAX, in default.c and fcstat.c files. --- src/fcdefault.c | 32 +++++++++++++++++++++++++------- src/fcstat.c | 28 +++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/fcdefault.c b/src/fcdefault.c index 6647a8f..4856777 100644 --- a/src/fcdefault.c +++ b/src/fcdefault.c @@ -150,15 +150,33 @@ retry: # if defined (HAVE_GETEXECNAME) const char *p = getexecname (); # elif defined (HAVE_READLINK) - char buf[PATH_MAX + 1]; - int len; + int size = 128; char *p = NULL; - len = readlink ("/proc/self/exe", buf, sizeof (buf) - 1); - if (len != -1) - { - buf[len] = '\0'; - p = buf; + while (1) { + char *buf = malloc (size); + int len; + + if (buf == NULL) + break; + + len = readlink ("/proc/self/exe", buf, size - 1); + + if (len < 0) + { + free(buf); + break; + } + + if (len < size - 1) + { + buf[len] = '\0'; + p = buf; + break; + } + + free (buf); + size *= 2; } # else char *p = NULL; diff --git a/src/fcstat.c b/src/fcstat.c index 1734fa4..b2a5ddb 100644 --- a/src/fcstat.c +++ b/src/fcstat.c @@ -278,17 +278,35 @@ FcDirChecksum (const FcChar8 *dir, time_t *checksum) { #endif struct stat statb; - char f[PATH_MAX + 1]; + int size = 128; + char *f = malloc (size); - memcpy (f, dir, len); - f[len] = FC_DIR_SEPARATOR; - memcpy (&f[len + 1], files[n]->d_name, dlen); - f[len + 1 + dlen] = 0; + if (f == NULL) + break; + + if (len < 0) + { + free(f); + break; + } + + if (len < size - 1) + { + memcpy (f, dir, len); + f[len] = FC_DIR_SEPARATOR; + memcpy (&f[len + 1], files[n]->d_name, dlen); + f[len + 1 + dlen] = 0; + } + if (lstat (f, &statb) < 0) { ret = -1; goto bail; } + + free (f); + size *= 2; + if (S_ISDIR (statb.st_mode)) goto bail; -- 2.6.3