From 1a44a463af542ca3f5692d1e99cc2a42881c05dc Mon Sep 17 00:00:00 2001 From: matz Date: Wed, 28 Aug 2002 06:01:58 +0000 Subject: [PATCH] * string.c (rb_str_delete_bang): should check if str->ptr is 0. * string.c (rb_str_squeeze_bang): ditto. * string.c (rb_str_count): ditto. * string.c (rb_str_lstrip_bang): ditto. * string.c (rb_str_rstrip_bang): ditto. * string.c (rb_str_intern): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2752 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 14 ++++++++++++++ configure.in | 3 ++- string.c | 15 +++++++++++++-- version.h | 4 ++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index e6ef5ed741..96def5e582 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Wed Aug 28 15:00:29 2002 Yukihiro Matsumoto + + * string.c (rb_str_delete_bang): should check if str->ptr is 0. + + * string.c (rb_str_squeeze_bang): ditto. + + * string.c (rb_str_count): ditto. + + * string.c (rb_str_lstrip_bang): ditto. + + * string.c (rb_str_rstrip_bang): ditto. + + * string.c (rb_str_intern): ditto. + Wed Aug 28 11:37:35 2002 NAKAMURA Usaku * win32/win32.h: define SIGINT and SIGKILL if not defined. diff --git a/configure.in b/configure.in index fcd77fba3e..f96249ad92 100644 --- a/configure.in +++ b/configure.in @@ -97,7 +97,8 @@ AC_PROG_GCC_TRADITIONAL AC_PROG_YACC AC_CHECK_TOOL(RANLIB, ranlib, :) -AC_CHECK_TOOL(AR, ar aal, ar) +AC_CHECK_TOOL(AR, ar) +AC_CHECK_PROGS(AR, ar aal, ar) case "$target_os" in cygwin*|mingw*) diff --git a/string.c b/string.c index 49b0c7add7..4f423daefe 100644 --- a/string.c +++ b/string.c @@ -2133,6 +2133,7 @@ tr_trans(str, src, repl, sflag) rb_str_modify(str); StringValue(src); StringValue(repl); + if (RSTRING(str)->len == 0 || !RSTRING(str)->ptr) return Qnil; trsrc.p = RSTRING(src)->ptr; trsrc.pend = trsrc.p + RSTRING(src)->len; if (RSTRING(src)->len >= 2 && RSTRING(src)->ptr[0] == '^') { cflag++; @@ -2288,6 +2289,7 @@ rb_str_delete_bang(argc, argv, str) rb_str_modify(str); s = t = RSTRING(str)->ptr; + if (!s || RSTRING(str)->len == 0) return Qnil; send = s + RSTRING(str)->len; while (s < send) { if (squeez[*s & 0xff]) @@ -2342,8 +2344,8 @@ rb_str_squeeze_bang(argc, argv, str) } rb_str_modify(str); - s = t = RSTRING(str)->ptr; + if (!s || RSTRING(str)->len == 0) return Qnil; send = s + RSTRING(str)->len; save = -1; while (s < send) { @@ -2412,6 +2414,7 @@ rb_str_count(argc, argv, str) } s = RSTRING(str)->ptr; + if (!s || RSTRING(str)->len == 0) return Qnil; send = s + RSTRING(str)->len; i = 0; while (s < send) { @@ -2795,6 +2798,7 @@ rb_str_lstrip_bang(str) rb_str_modify(str); s = RSTRING(str)->ptr; + if (!s || RSTRING(str)->len == 0) return Qnil; e = t = s + RSTRING(str)->len; /* remove spaces at head */ while (s < t && ISSPACE(*s)) s++; @@ -2825,6 +2829,7 @@ rb_str_rstrip_bang(str) rb_str_modify(str); s = RSTRING(str)->ptr; + if (!s || RSTRING(str)->len == 0) return Qnil; e = t = s + RSTRING(str)->len; /* remove trailing spaces */ @@ -2958,12 +2963,15 @@ rb_str_crypt(str, salt) { extern char *crypt(); VALUE result; + char *s; StringValue(salt); if (RSTRING(salt)->len < 2) rb_raise(rb_eArgError, "salt too short(need >=2 bytes)"); - result = rb_str_new2(crypt(RSTRING(str)->ptr, RSTRING(salt)->ptr)); + if (RSTRING(str)->ptr) s = RSTRING(str)->ptr; + else s = ""; + result = rb_str_new2(crypt(s, RSTRING(salt)->ptr)); OBJ_INFECT(result, str); OBJ_INFECT(result, salt); return result; @@ -2975,6 +2983,9 @@ rb_str_intern(str) { ID id; + if (!RSTRING(str)->ptr || RSTRING(str)->len == 0) { + rb_raise(rb_eArgError, "interning empty string"); + } if (strlen(RSTRING(str)->ptr) != RSTRING(str)->len) rb_raise(rb_eArgError, "string contains `\\0'"); id = rb_intern(RSTRING(str)->ptr); diff --git a/version.h b/version.h index 5f448bc1e2..c292fc58c6 100644 --- a/version.h +++ b/version.h @@ -1,4 +1,4 @@ #define RUBY_VERSION "1.7.3" -#define RUBY_RELEASE_DATE "2002-08-27" +#define RUBY_RELEASE_DATE "2002-08-28" #define RUBY_VERSION_CODE 173 -#define RUBY_RELEASE_CODE 20020827 +#define RUBY_RELEASE_CODE 20020828