core: object: add nullptr checks to data retrieval functions

This commit is contained in:
2025-10-25 00:00:37 +01:00
parent e499d8631f
commit 7c9a753007

View File

@@ -92,6 +92,10 @@ bool b_object_is_type(const struct _b_object *p, b_type type)
void *b_object_get_private(const struct _b_object *object, b_type type) void *b_object_get_private(const struct _b_object *object, b_type type)
{ {
if (!object) {
return NULL;
}
if (b_type_id_compare(&object->obj_type->r_info->t_id, type) == 0) { if (b_type_id_compare(&object->obj_type->r_info->t_id, type) == 0) {
return (char *)object + object->obj_main_priv_offset; return (char *)object + object->obj_main_priv_offset;
} }
@@ -107,6 +111,10 @@ void *b_object_get_private(const struct _b_object *object, b_type type)
void *b_object_get_protected(const struct _b_object *object, b_type type) void *b_object_get_protected(const struct _b_object *object, b_type type)
{ {
if (!object) {
return NULL;
}
struct b_type_component *comp struct b_type_component *comp
= b_type_get_component(&object->obj_type->r_components, type); = b_type_get_component(&object->obj_type->r_components, type);
if (!comp) { if (!comp) {
@@ -118,6 +126,10 @@ void *b_object_get_protected(const struct _b_object *object, b_type type)
void *b_object_get_interface(const struct _b_object *object, b_type type) void *b_object_get_interface(const struct _b_object *object, b_type type)
{ {
if (!object) {
return NULL;
}
return b_class_get_interface(object->obj_type->r_class, type); return b_class_get_interface(object->obj_type->r_class, type);
} }
@@ -125,6 +137,10 @@ enum b_status b_object_get_data(
const struct _b_object *object, b_type type, void **priv, void **prot, const struct _b_object *object, b_type type, void **priv, void **prot,
void **iface) void **iface)
{ {
if (!object) {
return B_ERR_INVALID_ARGUMENT;
}
struct b_type_component *comp struct b_type_component *comp
= b_type_get_component(&object->obj_type->r_components, type); = b_type_get_component(&object->obj_type->r_components, type);
if (!comp) { if (!comp) {