Fix bug in compiler error string construction.

PiperOrigin-RevId: 632404023
Change-Id: I79e24e44fc4eec67b76fbf62b053b169ba3070a3
This commit is contained in:
Yuval Tassa
2024-05-10 00:38:59 -07:00
committed by Copybara-Service
parent 1d181786a2
commit 39601b0f52
2 changed files with 19 additions and 1 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ static void checksize(double* size, mjtGeom type, mjCBase* object, const char* n
else {
for (int i=0; i<mjGEOMINFO[type]; i++) {
if (size[i]<=0) {
throw mjCError(object, "size %d must be positive in geom", "", i);
throw mjCError(object, "size %d must be positive in geom", nullptr, i);
}
}
}
+18
View File
@@ -395,6 +395,24 @@ TEST_F(XMLReaderTest, InvalidNumber) {
EXPECT_THAT(error.data(), HasSubstr("line 5"));
}
TEST_F(XMLReaderTest, InvalidNumberOfAttributes) {
static constexpr char xml[] = R"(
<mujoco>
<worldbody>
<body pos="0 0 .3">
<freejoint/>
<geom name="ellipsoid" type="ellipsoid" size=".1 .1"/>
</body>
</worldbody>
</mujoco>
)";
std::array<char, 1024> error;
mjModel* model = LoadModelFromString(xml, error.data(), error.size());
ASSERT_THAT(model, IsNull());
EXPECT_THAT(error.data(), HasSubstr("size 2 must be positive"));
EXPECT_THAT(error.data(), HasSubstr("line 6"));
}
TEST_F(XMLReaderTest, AllowsSpaces) {
static constexpr char xml[] = R"(
<mujoco>