summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-10 07:53:50 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-10-10 07:53:50 +0000
commit71bf4e63727a500b6f05882c11c5844afc71641b (patch)
tree2cb56138ab2179cd33fd29dc7ab087fa8d4eb6f9 /ext
parent9b2fa26be45b051ebdfc2cf06a13aff0caf58c00 (diff)
* ext/digest/digest.c (hexdigest_str_new, bubblebabble_str_new):
Perform StringValue() checks properly. * ext/digest/digest.c: Use RSTRING_{PTR,LEN} macros. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@11119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/digest/digest.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/ext/digest/digest.c b/ext/digest/digest.c
index 28338e8..38ba36f 100644
--- a/ext/digest/digest.c
+++ b/ext/digest/digest.c
@@ -42,8 +42,8 @@ get_digest_base_metadata(VALUE klass)
static VALUE
hexdigest_str_new(VALUE str_digest)
{
- char *digest = RSTRING_PTR(str_digest);
- size_t digest_len = RSTRING_LEN(str_digest);
+ char *digest;
+ size_t digest_len;
int i;
VALUE str;
char *p;
@@ -52,6 +52,10 @@ hexdigest_str_new(VALUE str_digest)
'a', 'b', 'c', 'd', 'e', 'f'
};
+ StringValue(str_digest);
+ digest = RSTRING_PTR(str_digest);
+ digest_len = RSTRING_LEN(str_digest);
+
if (LONG_MAX / 2 < digest_len) {
rb_raise(rb_eRuntimeError, "digest string too long");
}
@@ -71,8 +75,8 @@ hexdigest_str_new(VALUE str_digest)
static VALUE
bubblebabble_str_new(VALUE str_digest)
{
- char *digest = RSTRING_PTR(str_digest);
- size_t digest_len = RSTRING_LEN(str_digest);
+ char *digest;
+ size_t digest_len;
VALUE str;
char *p;
int i, j, seed = 1;
@@ -84,6 +88,10 @@ bubblebabble_str_new(VALUE str_digest)
'p', 'r', 's', 't', 'v', 'z', 'x'
};
+ StringValue(str_digest);
+ digest = RSTRING_PTR(str_digest);
+ digest_len = RSTRING_LEN(str_digest);
+
if ((LONG_MAX - 2) / 3 < (digest_len | 1)) {
rb_raise(rb_eRuntimeError, "digest string too long");
}
@@ -169,10 +177,10 @@ rb_digest_base_s_digest(VALUE klass, VALUE str)
Data_Get_Struct(obj, void, pctx);
StringValue(str);
- algo->update_func(pctx, RSTRING(str)->ptr, RSTRING(str)->len);
+ algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));
str = rb_str_new(0, algo->digest_len);
- algo->finish_func(pctx, RSTRING(str)->ptr);
+ algo->finish_func(pctx, RSTRING_PTR(str));
return str;
}
@@ -229,7 +237,7 @@ rb_digest_base_update(VALUE self, VALUE str)
Data_Get_Struct(self, void, pctx);
StringValue(str);
- algo->update_func(pctx, RSTRING(str)->ptr, RSTRING(str)->len);
+ algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));
return self;
}
@@ -252,7 +260,7 @@ rb_digest_base_lshift(VALUE self, VALUE str)
Data_Get_Struct(self, void, pctx);
StringValue(str);
- algo->update_func(pctx, RSTRING(str)->ptr, RSTRING(str)->len);
+ algo->update_func(pctx, RSTRING_PTR(str), RSTRING_LEN(str));
return self;
}
@@ -289,7 +297,7 @@ rb_digest_base_digest(VALUE self)
memcpy(pctx2, pctx1, ctx_size);
str = rb_str_new(0, algo->digest_len);
- algo->finish_func(pctx2, RSTRING(str)->ptr);
+ algo->finish_func(pctx2, RSTRING_PTR(str));
free(pctx2);
return str;
@@ -355,12 +363,12 @@ rb_digest_base_equal(VALUE self, VALUE other)
StringValue(other);
str2 = other;
- if (RSTRING(str2)->len == algo->digest_len)
+ if (RSTRING_LEN(str2) == algo->digest_len)
str1 = rb_digest_base_digest(self);
else
str1 = rb_digest_base_hexdigest(self);
- if (RSTRING(str1)->len == RSTRING(str2)->len
+ if (RSTRING_LEN(str1) == RSTRING_LEN(str2)
&& rb_str_cmp(str1, str2) == 0)
return Qtrue;