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:
committed by
Copybara-Service
parent
68718e76b1
commit
f556d4d94f
+10
-2
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user