summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-28 06:01:58 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-08-28 06:01:58 +0000
commit1a44a463af542ca3f5692d1e99cc2a42881c05dc (patch)
tree54c12c3e0d7dbd3e6cd3faf226555f1e856c9735 /string.c
parentc1454b3acbc28ea629b49ea758a1ba43b6fa01ee (diff)
* 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
Diffstat (limited to 'string.c')
-rw-r--r--string.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/string.c b/string.c
index 49b0c7a..4f423da 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);