libretro / gambatte-libretro

Hard fork of Gambatte to the libretro API.
http://sourceforge.net/projects/gambatte/
GNU General Public License v2.0
104 stars 78 forks source link

Core cannot handle null system directory #140

Closed geajack closed 2 years ago

geajack commented 5 years ago

Libretro provides a "RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY" environment variable, which according to the comments in the code is intended to be optional:

#define RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY 9
                                           /* const char ** --
                                            * Returns the "system" directory of the frontend.
                                            * This directory can be used to store system specific
                                            * content such as BIOSes, configuration data, etc.
                                            * The returned value can be NULL.
                                            * If so, no such directory is defined,
                                            * and it's up to the implementation to find a suitable directory.
                                            *
                                            * NOTE: Some cores used this folder also for "save" data such as
                                            * memory cards, etc, for lack of a better place to put it.
                                            * This is now discouraged, and if possible, cores should try to
                                            * use the new GET_SAVE_DIRECTORY.
                                            */

However, code in this project crashes if the libretro frontend gives a value of NULL:

// libgambatte/libretro/libretro.cpp:73
bool file_present_in_system(std::string fname)
{
   const char *systemdirtmp = NULL;
   bool worked = environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &systemdirtmp);
   if (!worked)
      return false;

   std::string fullpath  = systemdirtmp;
   fullpath             += "/";
   fullpath             += fname;

   RFILE *fp             = filestream_open(fullpath.c_str(), RETRO_VFS_FILE_ACCESS_READ,
         RETRO_VFS_FILE_ACCESS_HINT_NONE);

   if (fp)
   {
      filestream_close(fp);
      return true;
   }

   return false;
}

The line at which fullpath is declared raises an exception and kills the app. I'm only just getting started with libretro, but this seems like non-compliance with the spec.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/78574417-core-cannot-handle-null-system-directory?utm_campaign=plugin&utm_content=tracker%2F1258974&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F1258974&utm_medium=issues&utm_source=github).
negativeExponent commented 5 years ago
inactive123 commented 2 years ago

I have been told by @jdgleaver this should be fine now, closing...