Avoid out-of-bounds access when checking file extensions.

Include the '.' in the file extension check.

PiperOrigin-RevId: 474866478
Change-Id: I809ae975e4c8b00f17278735975a7d07e0748643
This commit is contained in:
Nimrod Gileadi
2022-09-16 11:48:49 -07:00
committed by Copybara-Service
parent 68718e76b1
commit f556d4d94f
9 changed files with 99 additions and 27 deletions
+10 -2
View File
@@ -19,6 +19,7 @@
#include <cstdio>
#include <limits>
#include <string>
#include <string_view>
#include <mujoco/mjtnum.h>
#include "engine/engine_macro.h"
@@ -488,9 +489,16 @@ string mjuu_stripext(string filename) {
}
// return name without extension
else {
return filename.substr(0, end);
return filename.substr(0, end);
}
string mjuu_getext(std::string_view filename) {
size_t dot = filename.find_last_of('.');
if (dot==string::npos) {
return "";
}
return string(filename.substr(dot, filename.size() - dot));
}