Fix null pointer deref for unknown class names.

PiperOrigin-RevId: 610391077
Change-Id: I5abd62ff46e31e788f06fe111adb3c25287d4fdc
This commit is contained in:
Yuval Tassa
2024-02-26 06:38:03 -08:00
committed by Copybara-Service
parent b47d97652e
commit 8679c9fc59
4 changed files with 46 additions and 5 deletions
+12
View File
@@ -346,6 +346,18 @@ mjmDefault* mjm_getDefault(mjElement element) {
// find default in model by class name
mjmDefault* mjm_findDefault(mjmModel* modelspec, const char* classname) {
mjCModel* model = reinterpret_cast<mjCModel*>(modelspec->element);
mjCDef* cdef = model->FindDef(classname);
if (!cdef) {
return nullptr;
}
return &cdef->spec;
}
// find body in model by name
mjmBody* mjm_findBody(mjmModel* modelspec, const char* name) {
mjCModel* model = reinterpret_cast<mjCModel*>(modelspec->element);
+3
View File
@@ -821,6 +821,9 @@ MJAPI mjmModel* mjm_getModel(mjmBody* body);
// Get default corresponding to an mjElement.
MJAPI mjmDefault* mjm_getDefault(mjElement element);
// Find default in model by class name.
MJAPI mjmDefault* mjm_findDefault(mjmModel* model, const char* classname);
// Find body in model by name.
MJAPI mjmBody* mjm_findBody(mjmModel* model, const char* name);