From 2a625db39df5e5e5f72556f0cd4a02005115c50f Mon Sep 17 00:00:00 2001 From: Clint Adams Date: Fri, 22 Sep 2000 22:16:15 +0000 Subject: 12859: dynamically-allocate buffer in ztat(), ztrdupstring() --- ChangeLog | 6 ++++++ Src/Zle/compresult.c | 14 ++++++-------- Src/string.c | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index acb35ef81..7281799b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2000-09-22 Clint Adams + + * 12859: Src/string.c, Src/Zle/compresult.c: + dynamically allocate buffer in ztat, remove + duplication loop to ztrdupstrip(). + 2000-09-20 Bart Schaefer * 12851, 12852: Completion/Commands/_expand_word, diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c index 19d785bb8..92bb2c803 100644 --- a/Src/Zle/compresult.c +++ b/Src/Zle/compresult.c @@ -731,19 +731,17 @@ do_ambiguous(void) mod_export int ztat(char *nam, struct stat *buf, int ls) { - char b[PATH_MAX], *p; + int e; + char *b; if (!(ls ? lstat(nam, buf) : stat(nam, buf))) return 0; - for (p = b; p < b + sizeof(b) - 1 && *nam; nam++) - if (*nam == '\\' && nam[1]) - *p++ = *++nam; - else - *p++ = *nam; - *p = '\0'; + b = ztrdupstrip(nam, '\\'); - return ls ? lstat(b, buf) : stat(b, buf); + e = ls ? lstat(b, buf) : stat(b, buf); + zsfree(b); + return e; } /* Insert a single match in the command line. */ diff --git a/Src/string.c b/Src/string.c index 3dad89911..57775359e 100644 --- a/Src/string.c +++ b/Src/string.c @@ -133,3 +133,23 @@ appstr(char *base, char const *append) { return strcat(realloc(base, strlen(base) + strlen(append) + 1), append); } + +/* Duplicate a string, stripping delimiters. */ + +/**/ +mod_export char * +ztrdupstrip(const char *nam, char delim) +{ + char *p, *buf; + + buf = zalloc(strlen(nam)); + + for (p = buf; *nam; nam++) + if (*nam == delim && nam[1]) + *p++ = *++nam; + else + *p++ = *nam; + *p = '\0'; + + return buf; +} -- cgit 1.4.1