summaryrefslogtreecommitdiff
path: root/ext/digest/digest.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/digest/digest.c')
-rw-r--r--ext/digest/digest.c32
1 files changed, 14 insertions, 18 deletions
diff --git a/ext/digest/digest.c b/ext/digest/digest.c
index d95f8a6976..dd78739b80 100644
--- a/ext/digest/digest.c
+++ b/ext/digest/digest.c
@@ -151,8 +151,7 @@ rb_digest_base_alloc(VALUE klass)
return Data_Wrap_Struct(klass, 0, free, 0);
}
- /* XXX: An uninitialized buffer may lead ALGO_Equal() to fail */
- pctx = xcalloc(algo->ctx_size, 1);
+ pctx = xmalloc(algo->ctx_size);
algo->init_func(pctx);
obj = Data_Wrap_Struct(klass, 0, free, pctx);
@@ -208,7 +207,7 @@ rb_digest_base_copy(VALUE copy, VALUE obj)
algo = get_digest_base_metadata(rb_obj_class(copy));
if (algo == NULL) {
- /* subclasses must define initialize_copy() */
+ /* initialize_copy() is undefined or something */
rb_notimplement();
}
@@ -375,25 +374,22 @@ rb_digest_base_equal(VALUE self, VALUE other)
VALUE str1, str2;
klass = rb_obj_class(self);
- algo = get_digest_base_metadata(klass);
if (rb_obj_class(other) == klass) {
- void *pctx1, *pctx2;
-
- Data_Get_Struct(self, void, pctx1);
- Data_Get_Struct(other, void, pctx2);
-
- return algo->equal_func(pctx1, pctx2) ? Qtrue : Qfalse;
+ str1 = rb_digest_base_digest(self);
+ str2 = rb_digest_base_digest(other);
+ } else {
+ StringValue(other);
+ str2 = other;
+
+ algo = get_digest_base_metadata(klass);
+
+ if (RSTRING_LEN(str2) == algo->digest_len)
+ str1 = rb_digest_base_digest(self);
+ else
+ str1 = rb_digest_base_hexdigest(self);
}
- StringValue(other);
- str2 = other;
-
- if (RSTRING_LEN(str2) == algo->digest_len)
- str1 = rb_digest_base_digest(self);
- else
- str1 = rb_digest_base_hexdigest(self);
-
if (RSTRING_LEN(str1) == RSTRING_LEN(str2)
&& rb_str_cmp(str1, str2) == 0)
return Qtrue;