core: class: validate magic number in class header

This commit is contained in:
2025-11-01 09:56:52 +00:00
parent 360428c8e8
commit abf1d45602

View File

@@ -2,6 +2,7 @@
#include "type.h"
#include <assert.h>
#include <blue/core/class.h>
#include <stdlib.h>
#include <string.h>
@@ -18,11 +19,23 @@ void *b_class_get(b_type id)
const char *b_class_get_name(const struct _b_class *c)
{
if (!c) {
return NULL;
}
assert(c->c_magic == B_CLASS_MAGIC);
return c->c_type->r_info->t_name;
}
void *b_class_get_interface(const struct _b_class *c, const union b_type *id)
{
if (!c) {
return NULL;
}
assert(c->c_magic == B_CLASS_MAGIC);
const struct b_type_registration *type_reg = c->c_type;
struct b_type_component *comp
= b_type_get_component(&type_reg->r_components, id);