diff --git a/ChangeLog b/ChangeLog index a9574a6598..47e30f1da1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon May 26 18:24:48 2008 Nobuyoshi Nakada + + * file.c (BUFCHECK): no resize if enough room. + + * file.c (file_expand_path): use BUFCHECK. + Mon May 26 17:48:42 2008 Akinori MUSHA * enumerator.c (struct enumerator, enumerator_init) diff --git a/file.c b/file.c index 86e51c871a..85152f70b7 100644 --- a/file.c +++ b/file.c @@ -2578,13 +2578,13 @@ ntfs_tail(const char *path) #define BUFCHECK(cond) do {\ long bdiff = p - buf;\ - while (cond) {\ - buflen *= 2;\ + if (!(cond)) {\ + do {buflen *= 2;} while (cond);\ + rb_str_resize(result, buflen);\ + buf = RSTRING_PTR(result);\ + p = buf + bdiff;\ + pend = buf + buflen;\ }\ - rb_str_resize(result, buflen);\ - buf = RSTRING_PTR(result);\ - p = buf + bdiff;\ - pend = buf + buflen;\ } while (0) #define BUFINIT() (\ @@ -2731,7 +2731,8 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result) if (p > buf && p[-1] == '/') --p; else { - BUFCHECK(bdiff >= ++buflen); + ++buflen; + BUFCHECK(bdiff >= buflen); *p = '/'; } @@ -2866,7 +2867,6 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result) #endif HANDLE h = FindFirstFile(b, &wfd); if (h != INVALID_HANDLE_VALUE) { - long bdiff; FindClose(h); p = strrdirsep(buf); len = strlen(wfd.cFileName); @@ -2877,10 +2877,8 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result) } #endif if (!p) p = buf; - buflen = ++p - buf + len; - bdiff = p - buf; - rb_str_resize(result, buflen); - p = RSTRING_PTR(result) + bdiff; + ++p; + BUFCHECK(bdiff + len >= buflen); memcpy(p, wfd.cFileName, len + 1); } }