core: class: validate magic number in class header
This commit is contained in:
13
core/class.c
13
core/class.c
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include "type.h"
|
#include "type.h"
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
#include <blue/core/class.h>
|
#include <blue/core/class.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.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)
|
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;
|
return c->c_type->r_info->t_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *b_class_get_interface(const struct _b_class *c, const union b_type *id)
|
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;
|
const struct b_type_registration *type_reg = c->c_type;
|
||||||
struct b_type_component *comp
|
struct b_type_component *comp
|
||||||
= b_type_get_component(&type_reg->r_components, id);
|
= b_type_get_component(&type_reg->r_components, id);
|
||||||
|
|||||||
Reference in New Issue
Block a user