summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-12-15 18:54:30 +0000
committer(no author) <(no author)@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-12-15 18:54:30 +0000
commit3f481aa21b7e178b9d0d8dfed0319e81d6bf2131 (patch)
tree7588e94fd99d085bbd448baa4ef59ef7d6dde7a3
parent74483e11f55124cf9cd679a8964614fe8b354e4f (diff)
This commit was manufactured by cvs2svn to create tag 'v1_8_5_10'.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_8_5_10@11397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog64
-rw-r--r--bignum.c5
-rw-r--r--configure.in2
-rw-r--r--dir.c76
-rw-r--r--ext/dbm/extconf.rb8
-rw-r--r--hash.c19
-rw-r--r--ia64.s33
-rw-r--r--lib/cgi.rb7
-rw-r--r--lib/rdoc/ri/ri_options.rb1
-rw-r--r--parse.y27
-rw-r--r--version.c4
-rw-r--r--version.h10
-rw-r--r--win32/win32.c59
13 files changed, 228 insertions, 87 deletions
diff --git a/ChangeLog b/ChangeLog
index 1825d8fa49..309c7a1cf6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,67 @@
+Fri Dec 15 17:21:14 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/rdoc/ri/ri_options.rb: prevent NameError. [ruby-dev:29597]
+
+Thu Dec 14 23:37:38 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * dir.c (glob_helper): get rid of possible memory leak.
+
+ * win32/win32.c (cmdglob, rb_w32_cmdvector, rb_w32_opendir,
+ rb_w32_get_environ): not to use GC before initialization.
+
+Wed Dec 6 19:53:41 2006 WATANABE Hirofumi <eban@ruby-lang.org>
+
+ * configure.in (SITE_DIR): fixed to emtpy RUBY_SITE_LIB in config.h on
+ NetBSD. fixed: [ruby-dev:29358]
+
+Mon Dec 4 10:43:46 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * parse.y (dyna_init_gen): dvar initialization only if dvar is
+ assigned inner block. [ruby-talk:227402]
+
+Mon Dec 4 10:22:26 2006 URABE Shyouhei <shyouhei@ice.uec.ac.jp>
+
+ * stable version 1.8.5-p2 relased.
+
+Sun Dec 3 17:11:12 2006 Shugo Maeda <shugo@ruby-lang.org>
+
+ * lib/cgi.rb (CGI::QueryExtension::read_multipart): should quote
+ boundary. JVN#84798830
+
+Sun Nov 26 16:36:46 2006 URABE Shyouhei <shyouhei@ruby-lang.org>
+
+ * version.h: addition of RUBY_PATCHLEVEL.
+ * version.c: ditto.
+
+Fri Nov 24 10:17:51 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * bignum.c (bignorm): avoid segmentation. a patch from Hiroyuki
+ Ito <ZXB01226@nifty.com>. [ruby-list:43012]
+
+Thu Nov 2 15:43:39 2006 NAKAMURA Usaku <usa@ruby-lang.org>
+
+ * parse.y (primary): should set NODE even when compstmt is NULL.
+ merge from trunk. fixed: [ruby-dev:29732]
+
+Sat Sep 23 21:34:15 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * lib/cgi.rb (CGI::QueryExtension::read_multipart): CGI content
+ may be empty. a patch from Jamis Buck <jamis at 37signals.com>.
+
+Mon Sep 4 21:43:57 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/dbm/extconf.rb: create makefile according to the result of check
+ for dbm header. fixed: [ruby-dev:29445]
+
+Tue Aug 29 19:10:10 2006 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * hash.c (rb_hash_s_create): fixed memory leak, based on the patch
+ by Kent Sibilev <ksruby at gmail.com>. fixed: [ruby-talk:211233]
+
+Fri Aug 25 17:15:17 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * stable version 1.8.5 released.
+
Fri Aug 25 17:02:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* gc.c (gc_sweep): typo fixed.
diff --git a/bignum.c b/bignum.c
index 6a7a83c085..493550ff98 100644
--- a/bignum.c
+++ b/bignum.c
@@ -99,7 +99,10 @@ static VALUE
bignorm(x)
VALUE x;
{
- if (!FIXNUM_P(x)) {
+ if (FIXNUM_P(x)) {
+ return x;
+ }
+ else if (TYPE(x) == T_BIGNUM) {
long len = RBIGNUM(x)->len;
BDIGIT *ds = BDIGITS(x);
diff --git a/configure.in b/configure.in
index 8ee5e6d871..b3288f8c03 100644
--- a/configure.in
+++ b/configure.in
@@ -1519,7 +1519,7 @@ AC_ARG_WITH(sitedir,
[ --with-sitedir=DIR site libraries in DIR [PREFIX/lib/ruby/site_ruby]],
[sitedir=$withval],
[sitedir='${prefix}/lib/ruby/site_ruby'])
-SITE_DIR="`eval \"echo ${sitedir}\"`"
+SITE_DIR=`eval echo \\"${sitedir}\\"`
case "$target_os" in
cygwin*|mingw*|*djgpp*|os2-emx*)
RUBY_SITE_LIB_PATH="`expr "$SITE_DIR" : "$prefix\(/.*\)"`" ||
diff --git a/dir.c b/dir.c
index fd677c898d..4ac9ca6953 100644
--- a/dir.c
+++ b/dir.c
@@ -158,7 +158,7 @@ fnmatch(pat, string, flags)
int period = !(flags & FNM_DOTMATCH);
int nocase = flags & FNM_CASEFOLD;
- while (c = *pat++) {
+ while ((c = *pat++) != '\0') {
switch (c) {
case '?':
if (!*s || ISDIRSEP(*s) || PERIOD(s))
@@ -821,7 +821,12 @@ sys_warning_1(mesg)
#define GLOB_VERBOSE (1U << (sizeof(int) * CHAR_BIT - 1))
#define sys_warning(val) \
- ((flags & GLOB_VERBOSE) && rb_protect((VALUE (*)_((VALUE)))sys_warning_1, (VALUE)(val), 0))
+ (void)((flags & GLOB_VERBOSE) && rb_protect((VALUE (*)_((VALUE)))sys_warning_1, (VALUE)(val), 0))
+
+#define GLOB_ALLOC(type) (type *)malloc(sizeof(type))
+#define GLOB_ALLOC_N(type, n) (type *)malloc(sizeof(type) * (n))
+#define GLOB_REALLOC_N(var, type, n) (type *)realloc((var), sizeof(type) * (n))
+#define GLOB_JUMP_TAG(status) ((status == -1) ? rb_memerror() : rb_jump_tag(status))
/* Return nonzero if S has any special globbing chars in it. */
static int
@@ -872,7 +877,8 @@ extract_path(p, pend)
int len;
len = pend - p;
- alloc = ALLOC_N(char, len+1);
+ alloc = GLOB_ALLOC_N(char, len+1);
+ if (!alloc) return NULL;
memcpy(alloc, p, len);
if (len > 1 && pend[-1] == '/'
#if defined DOSISH_DRIVE_LETTER
@@ -955,6 +961,7 @@ glob_helper(path, sub, flags, func, arg)
int status = 0;
char *buf = 0;
char *newpath = 0;
+ char *newbuf;
p = sub ? sub : path;
if (!has_magic(p, 0, flags)) {
@@ -963,6 +970,7 @@ glob_helper(path, sub, flags, func, arg)
#endif
{
newpath = strdup(path);
+ if (!newpath) return -1;
if (sub) {
p = newpath + (sub - path);
remove_backslashes(newpath + (sub - path));
@@ -981,7 +989,7 @@ glob_helper(path, sub, flags, func, arg)
we may want to know what is wrong. */
sys_warning(path);
}
- xfree(newpath);
+ if (newpath) free(newpath);
return status;
}
@@ -1000,10 +1008,18 @@ glob_helper(path, sub, flags, func, arg)
} *tmp, *link, **tail = &link;
base = extract_path(path, p);
+ if (!base) {
+ status = -1;
+ break;
+ }
if (path == p) dir = ".";
else dir = base;
magic = extract_elem(p);
+ if (!magic) {
+ status = -1;
+ break;
+ }
if (stat(dir, &st) < 0) {
if (errno != ENOENT)
sys_warning(dir);
@@ -1015,7 +1031,12 @@ glob_helper(path, sub, flags, func, arg)
if (m && strcmp(magic, "**") == 0) {
int n = strlen(base);
recursive = 1;
- REALLOC_N(buf, char, n+strlen(m)+3);
+ newbuf = GLOB_REALLOC_N(buf, char, n+strlen(m)+3);
+ if (!newbuf) {
+ status = -1;
+ goto finalize;
+ }
+ buf = newbuf;
sprintf(buf, "%s%s", base, *base ? m : m+1);
status = glob_helper(buf, buf+n, flags, func, arg);
if (status) goto finalize;
@@ -1046,7 +1067,12 @@ glob_helper(path, sub, flags, func, arg)
continue;
if (fnmatch("*", dp->d_name, flags) != 0)
continue;
- REALLOC_N(buf, char, strlen(base)+NAMLEN(dp)+strlen(m)+6);
+ newbuf = GLOB_REALLOC_N(buf, char, strlen(base)+NAMLEN(dp)+strlen(m)+6);
+ if (!newbuf) {
+ status = -1;
+ break;
+ }
+ buf = newbuf;
sprintf(buf, "%s%s%s", base, (BASE) ? "/" : "", dp->d_name);
if (lstat(buf, &st) < 0) {
if (errno != ENOENT)
@@ -1064,14 +1090,23 @@ glob_helper(path, sub, flags, func, arg)
continue;
}
if (fnmatch(magic, dp->d_name, flags) == 0) {
- REALLOC_N(buf, char, strlen(base)+NAMLEN(dp)+2);
+ newbuf = GLOB_REALLOC_N(buf, char, strlen(base)+NAMLEN(dp)+2);
+ if (!newbuf) {
+ status = -1;
+ break;
+ }
+ buf = newbuf;
sprintf(buf, "%s%s%s", base, (BASE) ? "/" : "", dp->d_name);
if (!m) {
status = glob_call_func(func, buf, arg);
if (status) break;
continue;
}
- tmp = ALLOC(struct d_link);
+ tmp = GLOB_ALLOC(struct d_link);
+ if (!tmp) {
+ status = -1;
+ break;
+ }
tmp->path = buf;
buf = 0;
*tail = tmp;
@@ -1091,7 +1126,12 @@ glob_helper(path, sub, flags, func, arg)
int len = strlen(link->path);
int mlen = strlen(m);
- REALLOC_N(buf, char, len+mlen+1);
+ newbuf = GLOB_REALLOC_N(buf, char, len+mlen+1);
+ if (!newbuf) {
+ status = -1;
+ goto next_elem;
+ }
+ buf = newbuf;
sprintf(buf, "%s%s", link->path, m);
status = glob_helper(buf, buf+len, flags, func, arg);
}
@@ -1100,6 +1140,7 @@ glob_helper(path, sub, flags, func, arg)
sys_warning(link->path);
}
}
+ next_elem:
tmp = link;
link = link->next;
free(tmp->path);
@@ -1110,8 +1151,8 @@ glob_helper(path, sub, flags, func, arg)
}
p = m;
}
- xfree(buf);
- xfree(newpath);
+ if (buf) free(buf);
+ if (newpath) free(newpath);
return status;
}
@@ -1211,7 +1252,7 @@ push_braces(ary, str, flags)
int flags;
{
char *buf = 0;
- char *b;
+ char *b, *newbuf;
const char *s, *p, *t;
const char *lbrace, *rbrace;
int nest = 0;
@@ -1249,7 +1290,12 @@ push_braces(ary, str, flags)
}
}
}
- REALLOC_N(buf, char, len+1);
+ newbuf = GLOB_REALLOC_N(buf, char, len+1);
+ if (!newbuf) {
+ status = -1;
+ break;
+ }
+ buf = newbuf;
memcpy(buf, s, lbrace-s);
b = buf + (lbrace-s);
memcpy(b, t, p-t);
@@ -1261,7 +1307,7 @@ push_braces(ary, str, flags)
else {
status = push_globs(ary, str, flags);
}
- xfree(buf);
+ if (buf) free(buf);
return status;
}
@@ -1306,7 +1352,7 @@ rb_push_glob(str, flags)
}
/* else unmatched braces */
}
- if (status) rb_jump_tag(status);
+ if (status) GLOB_JUMP_TAG(status);
if (rb_block_given_p()) {
rb_ary_each(ary);
return Qnil;
diff --git a/ext/dbm/extconf.rb b/ext/dbm/extconf.rb
index 19bfc1f6d3..52ec688952 100644
--- a/ext/dbm/extconf.rb
+++ b/ext/dbm/extconf.rb
@@ -46,16 +46,16 @@ def db_prefix(func)
end
if dblib
- db_check(dblib)
+ dbm_hdr = db_check(dblib)
else
- for dblib in %w(db db2 db1 dbm gdbm gdbm_compat qdbm)
- db_check(dblib) and break
+ dbm_hdr = %w(db db2 db1 dbm gdbm gdbm_compat qdbm).any? do |dblib|
+ db_check(dblib)
end
end
have_header("cdefs.h")
have_header("sys/cdefs.h")
-if /DBM_HDR/ =~ $CFLAGS and have_func(db_prefix("dbm_open"))
+if dbm_hdr and have_func(db_prefix("dbm_open"))
have_func(db_prefix("dbm_clearerr")) unless $dbm_conf_have_gdbm
create_makefile("dbm")
end
diff --git a/hash.c b/hash.c
index dc804ebd34..0d4d43315b 100644
--- a/hash.c
+++ b/hash.c
@@ -223,20 +223,31 @@ rb_hash_foreach(hash, func, farg)
rb_ensure(hash_foreach_call, (VALUE)&arg, hash_foreach_ensure, hash);
}
+static VALUE hash_alloc0 _((VALUE));
static VALUE hash_alloc _((VALUE));
static VALUE
-hash_alloc(klass)
+hash_alloc0(klass)
VALUE klass;
{
NEWOBJ(hash, struct RHash);
OBJSETUP(hash, klass, T_HASH);
hash->ifnone = Qnil;
- hash->tbl = st_init_table(&objhash);
return (VALUE)hash;
}
+static VALUE
+hash_alloc(klass)
+ VALUE klass;
+{
+ VALUE hash = hash_alloc0(klass);
+
+ RHASH(hash)->tbl = st_init_table(&objhash);
+
+ return hash;
+}
+
VALUE
rb_hash_new()
{
@@ -325,9 +336,7 @@ rb_hash_s_create(argc, argv, klass)
int i;
if (argc == 1 && TYPE(argv[0]) == T_HASH) {
- hash = hash_alloc(klass);
-
- RHASH(hash)->ifnone = Qnil;
+ hash = hash_alloc0(klass);
RHASH(hash)->tbl = st_copy(RHASH(argv[0])->tbl);
return hash;
diff --git a/ia64.s b/ia64.s
deleted file mode 100644
index ba5241daf2..0000000000
--- a/ia64.s
+++ /dev/null
@@ -1,33 +0,0 @@
-// rb_ia64_flushrs and rb_ia64_bsp is written in IA64 assembly language
-// because Intel Compiler for IA64 doesn't support inline assembly.
-//
-// This file is based on following C program compiled by gcc.
-//
-// void rb_ia64_flushrs(void) { __builtin_ia64_flushrs(); }
-// void *rb_ia64_bsp(void) { return __builtin_ia64_bsp(); }
-//
- .file "ia64.c"
- .text
- .align 16
- .global rb_ia64_flushrs#
- .proc rb_ia64_flushrs#
-rb_ia64_flushrs:
- .prologue
- .body
- flushrs
- ;;
- nop.i 0
- br.ret.sptk.many b0
- .endp rb_ia64_flushrs#
- .align 16
- .global rb_ia64_bsp#
- .proc rb_ia64_bsp#
-rb_ia64_bsp:
- .prologue
- .body
- nop.m 0
- ;;
- mov r8 = ar.bsp
- br.ret.sptk.many b0
- .endp rb_ia64_bsp#
- .ident "GCC: (GNU) 3.3.5 (Debian 1:3.3.5-13)"
diff --git a/lib/cgi.rb b/lib/cgi.rb
index 1598df89f2..ac80d91799 100644
--- a/lib/cgi.rb
+++ b/lib/cgi.rb
@@ -967,6 +967,7 @@ class CGI
def read_multipart(boundary, content_length)
params = Hash.new([])
boundary = "--" + boundary
+ quoted_boundary = Regexp.quote(boundary, "n")
buf = ""
bufsize = 10 * 1024
boundary_end=""
@@ -998,7 +999,7 @@ class CGI
end
body.binmode if defined? body.binmode
- until head and /#{boundary}(?:#{EOL}|--)/n.match(buf)
+ until head and /#{quoted_boundary}(?:#{EOL}|--)/n.match(buf)
if (not head) and /#{EOL}#{EOL}/n.match(buf)
buf = buf.sub(/\A((?:.|\n)*?#{EOL})#{EOL}/n) do
@@ -1018,14 +1019,14 @@ class CGI
else
stdinput.read(content_length)
end
- if c.nil?
+ if c.nil? || c.empty?
raise EOFError, "bad content body"
end
buf.concat(c)
content_length -= c.size
end
- buf = buf.sub(/\A((?:.|\n)*?)(?:[\r\n]{1,2})?#{boundary}([\r\n]{1,2}|--)/n) do
+ buf = buf.sub(/\A((?:.|\n)*?)(?:[\r\n]{1,2})?#{quoted_boundary}([\r\n]{1,2}|--)/n) do
body.print $1
if "--" == $2
content_length = -1
diff --git a/lib/rdoc/ri/ri_options.rb b/lib/rdoc/ri/ri_options.rb
index 91a28e1ab4..db9f4afecf 100644
--- a/lib/rdoc/ri/ri_options.rb
+++ b/lib/rdoc/ri/ri_options.rb
@@ -3,6 +3,7 @@
module RI
+ require 'rdoc/ri/ri_paths'
require 'rdoc/ri/ri_display'
VERSION_STRING = "ri v1.0.1 - 20041108"
diff --git a/parse.y b/parse.y
index e2982f2c80..14561ca185 100644
--- a/parse.y
+++ b/parse.y
@@ -1481,7 +1481,8 @@ primary : literal
}
| tLPAREN compstmt ')'
{
- $$ = $2;
+ if (!$2) $$ = NEW_NIL();
+ else $$ = $2;
}
| primary_value tCOLON2 tCONSTANT
{
@@ -4865,6 +4866,8 @@ gettable(id)
return 0;
}
+static VALUE dyna_var_lookup _((ID id));
+
static NODE*
assignable(id, val)
ID id;
@@ -4893,7 +4896,7 @@ assignable(id, val)
if (rb_dvar_curr(id)) {
return NEW_DASGN_CURR(id, val);
}
- else if (rb_dvar_defined(id)) {
+ else if (dyna_var_lookup(id)) {
return NEW_DASGN(id, val);
}
else if (local_id(id) || !dyna_in_block()) {
@@ -5735,6 +5738,22 @@ top_local_setup()
local_pop();
}
+static VALUE
+dyna_var_lookup(id)
+ ID id;
+{
+ struct RVarmap *vars = ruby_dyna_vars;
+
+ while (vars) {
+ if (vars->id == id) {
+ vars->val = Qtrue;
+ return Qtrue;
+ }
+ vars = vars->next;
+ }
+ return Qfalse;
+}
+
static struct RVarmap*
dyna_push()
{
@@ -5769,7 +5788,9 @@ dyna_init(node, pre)
if (!node || !post || pre == post) return node;
for (var = 0; post != pre && post->id; post = post->next) {
- var = NEW_DASGN_CURR(post->id, var);
+ if (RTEST(post->val)) {
+ var = NEW_DASGN_CURR(post->id, var);
+ }
}
return block_append(var, node);
}
diff --git a/version.c b/version.c
index 63c519a6f4..b235673001 100644
--- a/version.c
+++ b/version.c
@@ -17,6 +17,7 @@
const char ruby_version[] = RUBY_VERSION;
const char ruby_release_date[] = RUBY_RELEASE_DATE;
const char ruby_platform[] = RUBY_PLATFORM;
+const int ruby_patchlevel = RUBY_PATCHLEVEL;
void
Init_version()
@@ -28,6 +29,7 @@ Init_version()
rb_define_global_const("RUBY_VERSION", v);
rb_define_global_const("RUBY_RELEASE_DATE", d);
rb_define_global_const("RUBY_PLATFORM", p);
+ rb_define_global_const("RUBY_PATCHLEVEL", INT2FIX(RUBY_PATCHLEVEL));
/* obsolete constants */
rb_define_global_const("VERSION", v);
@@ -38,7 +40,7 @@ Init_version()
void
ruby_show_version()
{
- printf("ruby %s (%s) [%s]\n", RUBY_VERSION, RUBY_RELEASE_DATE, RUBY_PLATFORM);
+ printf("ruby %s (%s patchlevel %d) [%s]\n", RUBY_VERSION, RUBY_RELEASE_DATE, RUBY_PATCHLEVEL, RUBY_PLATFORM);
fflush(stdout);
}
diff --git a/version.h b/version.h
index a2c1803310..adc3d92194 100644
--- a/version.h
+++ b/version.h
@@ -1,15 +1,17 @@
#define RUBY_VERSION "1.8.5"
-#define RUBY_RELEASE_DATE "2006-08-23"
+#define RUBY_RELEASE_DATE "2006-12-16"
#define RUBY_VERSION_CODE 185
-#define RUBY_RELEASE_CODE 20060823
+#define RUBY_RELEASE_CODE 20061216
+#define RUBY_PATCHLEVEL 10
#define RUBY_VERSION_MAJOR 1
#define RUBY_VERSION_MINOR 8
#define RUBY_VERSION_TEENY 5
#define RUBY_RELEASE_YEAR 2006
-#define RUBY_RELEASE_MONTH 8
-#define RUBY_RELEASE_DAY 23
+#define RUBY_RELEASE_MONTH 12
+#define RUBY_RELEASE_DAY 16
RUBY_EXTERN const char ruby_version[];
RUBY_EXTERN const char ruby_release_date[];
RUBY_EXTERN const char ruby_platform[];
+RUBY_EXTERN const int ruby_patchlevel;
diff --git a/win32/win32.c b/win32/win32.c
index e8ac1bbf07..f12100d68d 100644
--- a/win32/win32.c
+++ b/win32/win32.c
@@ -431,7 +431,8 @@ getlogin()
if (NTLoginName == NULL) {
if (GetUserName(buffer, &len)) {
- NTLoginName = ALLOC_N(char, len+1);
+ NTLoginName = (char *)malloc(len+1);
+ if (!NTLoginName) return NULL;
strncpy(NTLoginName, buffer, len);
NTLoginName[len] = '\0';
}
@@ -1068,10 +1069,12 @@ insert(const char *path, VALUE vinfo)
NtCmdLineElement *tmpcurr;
NtCmdLineElement ***tail = (NtCmdLineElement ***)vinfo;
- tmpcurr = ALLOC(NtCmdLineElement);
+ tmpcurr = (NtCmdLineElement *)malloc(sizeof(NtCmdLineElement));
+ if (!tmpcurr) return -1;
MEMZERO(tmpcurr, NtCmdLineElement, 1);
tmpcurr->len = strlen(path);
- tmpcurr->str = ALLOC_N(char, tmpcurr->len + 1);
+ tmpcurr->str = (char *)malloc(tmpcurr->len + 1);
+ if (!tmpcurr->str) return -1;
tmpcurr->flags |= NTMALLOC;
strcpy(tmpcurr->str, path);
**tail = tmpcurr;
@@ -1093,20 +1096,21 @@ cmdglob(NtCmdLineElement *patt, NtCmdLineElement **tail)
char buffer[MAXPATHLEN], *buf = buffer;
char *p;
NtCmdLineElement **last = tail;
+ int status;
if (patt->len >= MAXPATHLEN)
- buf = ruby_xmalloc(patt->len + 1);
+ if (!(buf = malloc(patt->len + 1))) return 0;
strncpy (buf, patt->str, patt->len);
buf[patt->len] = '\0';
for (p = buf; *p; p = CharNext(p))
if (*p == '\\')
*p = '/';
- ruby_globi(buf, 0, insert, (VALUE)&tail);
+ status = ruby_globi(buf, 0, insert, (VALUE)&tail);
if (buf != buffer)
free(buf);
- if (last == tail) return 0;
+ if (status || last == tail) return 0;
if (patt->flags & NTMALLOC)
free(patt->str);
free(patt);
@@ -1333,8 +1337,8 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
}
}
- curr = ALLOC(NtCmdLineElement);
- MEMZERO(curr, NtCmdLineElement, 1);
+ curr = (NtCmdLineElement *)calloc(sizeof(NtCmdLineElement), 1);
+ if (!curr) goto do_nothing;
curr->str = base;
curr->len = len;
@@ -1359,7 +1363,18 @@ rb_w32_cmdvector(const char *cmd, char ***vec)
}
len = (elements+1)*sizeof(char *) + strsz;
- buffer = ALLOC_N(char, len);
+ buffer = (char *)malloc(len);
+ if (!buffer) {
+ do_nothing:
+ while (curr = cmdhead) {
+ cmdhead = curr->next;
+ if (curr->flags & NTMALLOC) free(curr->str);
+ free(curr);
+ }
+ free(cmdline);
+ for (vptr = *vec; *vptr; ++vptr);
+ return vptr - *vec;
+ }
//
// make vptr point to the start of the buffer
@@ -1456,6 +1471,7 @@ rb_w32_opendir(const char *filename)
fh = FindFirstFile(scanname, &fd);
if (fh == INVALID_HANDLE_VALUE) {
errno = map_errno(GetLastError());
+ free(p);
return NULL;
}
@@ -1465,7 +1481,13 @@ rb_w32_opendir(const char *filename)
//
idx = strlen(fd.cFileName)+1;
- p->start = ALLOC_N(char, idx);
+ if (!(p->start = (char *)malloc(idx))) {
+ error:
+ rb_w32_closedir(p);
+ FindClose(fh);
+ errno = ENOMEM;
+ return NULL;
+ }
strcpy(p->start, fd.cFileName);
p->nfiles++;
@@ -1476,6 +1498,8 @@ rb_w32_opendir(const char *filename)
// of the previous string found.
//
while (FindNextFile(fh, &fd)) {
+ char *newpath;
+
len = strlen(fd.cFileName);
//
@@ -1483,12 +1507,11 @@ rb_w32_opendir(const char *filename)
// new name and it's null terminator
//
- #define Renew(x, y, z) (x = (z *)xrealloc(x, y))
-
- Renew (p->start, idx+len+1, char);
- if (p->start == NULL) {
- rb_fatal ("opendir: malloc failed!\n");
+ newpath = (char *)realloc(p->start, idx+len+1);
+ if (newpath == NULL) {
+ goto error;
}
+ p->start = newpath;
strcpy(&p->start[idx], fd.cFileName);
p->nfiles++;
idx += len+1;
@@ -3519,10 +3542,12 @@ rb_w32_get_environ(void)
for (env = envtop, num = 0; *env; env += strlen(env) + 1)
if (*env != '=') num++;
- myenvtop = ALLOC_N(char*, num + 1);
+ myenvtop = (char **)malloc(sizeof(char *) * (num + 1));
for (env = envtop, myenv = myenvtop; *env; env += strlen(env) + 1) {
if (*env != '=') {
- *myenv = ALLOC_N(char, strlen(env) + 1);
+ if (!(*myenv = (char *)malloc(strlen(env) + 1))) {
+ break;
+ }
strcpy(*myenv, env);
myenv++;
}