* file.c (BUFCHECK): no resize if enough room.
* file.c (file_expand_path): use BUFCHECK. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
71b059e070
commit
c3b10e7fcb
@ -1,3 +1,9 @@
|
|||||||
|
Mon May 26 18:24:48 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* file.c (BUFCHECK): no resize if enough room.
|
||||||
|
|
||||||
|
* file.c (file_expand_path): use BUFCHECK.
|
||||||
|
|
||||||
Mon May 26 17:48:42 2008 Akinori MUSHA <knu@iDaemons.org>
|
Mon May 26 17:48:42 2008 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* enumerator.c (struct enumerator, enumerator_init)
|
* enumerator.c (struct enumerator, enumerator_init)
|
||||||
|
22
file.c
22
file.c
@ -2578,13 +2578,13 @@ ntfs_tail(const char *path)
|
|||||||
|
|
||||||
#define BUFCHECK(cond) do {\
|
#define BUFCHECK(cond) do {\
|
||||||
long bdiff = p - buf;\
|
long bdiff = p - buf;\
|
||||||
while (cond) {\
|
if (!(cond)) {\
|
||||||
buflen *= 2;\
|
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)
|
} while (0)
|
||||||
|
|
||||||
#define BUFINIT() (\
|
#define BUFINIT() (\
|
||||||
@ -2731,7 +2731,8 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result)
|
|||||||
if (p > buf && p[-1] == '/')
|
if (p > buf && p[-1] == '/')
|
||||||
--p;
|
--p;
|
||||||
else {
|
else {
|
||||||
BUFCHECK(bdiff >= ++buflen);
|
++buflen;
|
||||||
|
BUFCHECK(bdiff >= buflen);
|
||||||
*p = '/';
|
*p = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2866,7 +2867,6 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result)
|
|||||||
#endif
|
#endif
|
||||||
HANDLE h = FindFirstFile(b, &wfd);
|
HANDLE h = FindFirstFile(b, &wfd);
|
||||||
if (h != INVALID_HANDLE_VALUE) {
|
if (h != INVALID_HANDLE_VALUE) {
|
||||||
long bdiff;
|
|
||||||
FindClose(h);
|
FindClose(h);
|
||||||
p = strrdirsep(buf);
|
p = strrdirsep(buf);
|
||||||
len = strlen(wfd.cFileName);
|
len = strlen(wfd.cFileName);
|
||||||
@ -2877,10 +2877,8 @@ file_expand_path(VALUE fname, VALUE dname, VALUE result)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!p) p = buf;
|
if (!p) p = buf;
|
||||||
buflen = ++p - buf + len;
|
++p;
|
||||||
bdiff = p - buf;
|
BUFCHECK(bdiff + len >= buflen);
|
||||||
rb_str_resize(result, buflen);
|
|
||||||
p = RSTRING_PTR(result) + bdiff;
|
|
||||||
memcpy(p, wfd.cFileName, len + 1);
|
memcpy(p, wfd.cFileName, len + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user