summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-09 09:30:25 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-04-09 09:30:25 +0000
commite32da15f48189cfba02a9be2e6572161d91b3122 (patch)
tree47c660015f96f23220975c71fd69e71f8a69b6ef /string.c
parent8673eacafa039f056927e0f91ce195afae9b9019 (diff)
1.1b9_09 pre
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'string.c')
-rw-r--r--string.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/string.c b/string.c
index 1b4a984ad35..086c8723406 100644
--- a/string.c
+++ b/string.c
@@ -44,6 +44,7 @@ str_new(ptr, len)
if (rb_safe_level() >= 3) {
FL_SET(str, STR_TAINT);
}
+ str->ptr = 0;
str->len = len;
str->orig = 0;
str->ptr = ALLOC_N(char,len+1);
@@ -483,7 +484,9 @@ str_cmp(str1, str2)
len = min(RSTRING(str1)->len, RSTRING(str2)->len);
retval = memcmp(RSTRING(str1)->ptr, RSTRING(str2)->ptr, len);
if (retval == 0) {
- retval = RSTRING(str1)->ptr[len] - RSTRING(str2)->ptr[len];
+ if (RSTRING(str1)->len == RSTRING(str2)->len) return 0;
+ if (RSTRING(str1)->len > RSTRING(str2)->len) return 1;
+ return -1;
}
if (retval == 0) return 0;
if (retval > 0) return 1;
@@ -2288,6 +2291,7 @@ str_chomp_bang(argc, argv, str)
}
if (len < RSTRING(str)->len) {
RSTRING(str)->len = len;
+ RSTRING(str)->ptr[len] = '\0';
return str;
}
return Qnil;
@@ -2299,6 +2303,7 @@ str_chomp_bang(argc, argv, str)
(rslen <= 1 ||
memcmp(RSTRING(rs)->ptr, p+len-rslen, rslen) == 0)) {
RSTRING(str)->len -= rslen;
+ RSTRING(str)->ptr[RSTRING(str)->len] = '\0';
return str;
}
return Qnil;