Correctly validate the size of user sensors in mj_validateReference.

PiperOrigin-RevId: 494877162
Change-Id: I0a070d7813efea6216d15270f62b6009c55e1a54
This commit is contained in:
Nimrod Gileadi
2022-12-12 17:48:23 -08:00
committed by Copybara-Service
parent 21f10ce1b6
commit 7076da6909
2 changed files with 22 additions and 3 deletions
+3 -3
View File
@@ -1209,7 +1209,7 @@ void mj_deleteData(mjData* d) {
const int nPOS[4] = {7, 4, 1, 1};
const int nVEL[4] = {6, 3, 1, 1};
static int sensorSize(mjtSensor sensor_type, int nuser_sensor) {
static int sensorSize(mjtSensor sensor_type, int sensor_dim) {
switch (sensor_type) {
case mjSENS_TOUCH:
case mjSENS_RANGEFINDER:
@@ -1254,7 +1254,7 @@ static int sensorSize(mjtSensor sensor_type, int nuser_sensor) {
return 4;
case mjSENS_USER:
return nuser_sensor;
return sensor_dim;
case mjSENS_PLUGIN:
return -1;
@@ -1593,7 +1593,7 @@ const char* mj_validateReferences(const mjModel* m) {
}
sensor_size = plugin->nsensordata(m, m->sensor_plugin[i], i);
} else {
sensor_size = sensorSize(sensor_type, m->nuser_sensor);
sensor_size = sensorSize(sensor_type, m->sensor_dim[i]);
}
if (sensor_size < 0) {
return "Invalid model: Bad sensor_type.";