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.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/ext/digest/digest.c b/ext/digest/digest.c
index 73655c5bb5..a59f880ac7 100644
--- a/ext/digest/digest.c
+++ b/ext/digest/digest.c
@@ -554,10 +554,22 @@ get_digest_base_metadata(VALUE klass)
if (NIL_P(p))
rb_raise(rb_eRuntimeError, "Digest::Base cannot be directly inherited in Ruby");
+ if (!RB_TYPE_P(obj, T_DATA) || RTYPEDDATA_P(obj)) {
+ wrong:
+ if (p == klass)
+ rb_raise(rb_eTypeError, "%"PRIsVALUE"::metadata is not initialized properly",
+ klass);
+ else
+ rb_raise(rb_eTypeError, "%"PRIsVALUE"(%"PRIsVALUE")::metadata is not initialized properly",
+ klass, p);
+ }
+
#undef RUBY_UNTYPED_DATA_WARNING
#define RUBY_UNTYPED_DATA_WARNING 0
Data_Get_Struct(obj, rb_digest_metadata_t, algo);
+ if (!algo) goto wrong;
+
switch (algo->api_version) {
case 3:
break;