libretro / dosbox-svn

GNU General Public License v2.0
6 stars 17 forks source link

Fix logic error that assumed normalized path #81

Closed N7Alpha closed 2 years ago

N7Alpha commented 2 years ago

It looks like gamePath is assumed to already be normalized with normalize_path here. Without this change it isn't though.

So the problem is if you pass a path like "C:/program.exe" to retro_load_game on Windows when dir is extracted it will equal "C:/program.exe" instead of "C:/". This is because std::string::find_last_of is looking for the Windows \ path separator and not the / one. This would work as intended if gamePath was normalized though.

realnc commented 2 years ago

Just get rid of tmp and do:

         {
             /* Copy the game path */
             loadPath = normalize_path(game->path);
+            gamePath = loadPath;
             const size_t lastDot = loadPath.find_last_of('.');
-            char tmp[PATH_MAX_LENGTH];
-            snprintf(tmp, sizeof(tmp), "%s", game->path);
-            gamePath = std::string(tmp);
N7Alpha commented 2 years ago

Yeah that makes sense to me. I've updated the PR accordingly.

realnc commented 2 years ago

Thanks. Merged.

Just in case you didn't know, this core is a bit outdated (it's based on dosbox sources from 2020.) No active development is happening anymore other than some bugfixes (like this one). If possible, you should switch to DOSBox-core, which is maintained and up to date with upstream dosbox and has a lot of enhancements.