Skip to content

Commit ac48742

Browse files
kbayescopybara-github
authored andcommitted
Support NULL in dir parameter in mj_addFileVFS.
Fixes #2839. PiperOrigin-RevId: 807208005 Change-Id: I8def3b1e388dc19fa2fa8a92d53abef30dee5b88
1 parent dd398f4 commit ac48742

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/user/user_vfs.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ int mj_addFileVFS(mjVFS* vfs, const char* directory, const char* filename) {
219219
VFS* cvfs = GetVFSImpl(vfs);
220220

221221
// make full name
222-
FilePath fullname = FilePath(directory, filename);
222+
const char* dir = directory != nullptr ? directory : "";
223+
FilePath fullname = FilePath(dir, filename);
223224

224225
// strip path
225226
FilePath newname = StripPath(filename);

test/user/user_vfs_test.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ TEST_F(UserVfsTest, AddFileStripPath) {
106106
mj_deleteVFS(&vfs);
107107
}
108108

109+
TEST_F(UserVfsTest, NullDirectory) {
110+
mjVFS vfs;
111+
mj_defaultVFS(&vfs);
112+
113+
const std::string file = "engine/testdata/actuation/activation.xml";
114+
const std::string path = GetTestDataFilePath(file);
115+
mj_addFileVFS(&vfs, nullptr, path.c_str());
116+
117+
EXPECT_TRUE(HasFile(&vfs, "activation.xml"));
118+
mj_deleteVFS(&vfs);
119+
}
120+
109121
TEST_F(UserVfsTest, AddFileRepeat) {
110122
mjVFS vfs;
111123
mj_defaultVFS(&vfs);

0 commit comments

Comments
 (0)