mirror of https://github.com/stella-emu/stella.git
Fix coverity complaining about unrestricted use of getenv.
This commit is contained in:
parent
7cc49b4ff1
commit
8a0491f3d3
|
@ -245,6 +245,18 @@ namespace BSPF
|
||||||
#endif
|
#endif
|
||||||
return tm_snapshot;
|
return tm_snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Coverity complains if 'getenv' is used unrestricted
|
||||||
|
inline string getenv(const string& env_var)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
string result(std::getenv(env_var.c_str()));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
catch(...) {
|
||||||
|
return EmptyString;
|
||||||
|
}
|
||||||
|
}
|
||||||
} // namespace BSPF
|
} // namespace BSPF
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -156,7 +156,7 @@ void MT24LC256::systemReset()
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
void MT24LC256::eraseAll()
|
void MT24LC256::eraseAll()
|
||||||
{
|
{
|
||||||
myData.fill(INIT_VALUE);
|
myData.fill(INITIAL_VALUE);
|
||||||
myDataChanged = true;
|
myDataChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ void MT24LC256::eraseCurrent()
|
||||||
{
|
{
|
||||||
if(myPageHit[page])
|
if(myPageHit[page])
|
||||||
{
|
{
|
||||||
std::fill_n(myData.begin() + page * PAGE_SIZE, PAGE_SIZE, INIT_VALUE);
|
std::fill_n(myData.begin() + page * PAGE_SIZE, PAGE_SIZE, INITIAL_VALUE);
|
||||||
myDataChanged = true;
|
myDataChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ void MT24LC256::jpee_init()
|
||||||
jpee_smallmode = 0;
|
jpee_smallmode = 0;
|
||||||
jpee_logmode = -1;
|
jpee_logmode = -1;
|
||||||
if(!myDataFileExists)
|
if(!myDataFileExists)
|
||||||
myData.fill(INIT_VALUE);
|
myData.fill(INITIAL_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
|
@ -51,7 +51,7 @@ class MT24LC256
|
||||||
static constexpr uInt32 PAGE_NUM = FLASH_SIZE / PAGE_SIZE;
|
static constexpr uInt32 PAGE_NUM = FLASH_SIZE / PAGE_SIZE;
|
||||||
|
|
||||||
// Initial state value of flash EEPROM
|
// Initial state value of flash EEPROM
|
||||||
static constexpr uInt8 INIT_VALUE = 0xff;
|
static constexpr uInt8 INITIAL_VALUE = 0xff;
|
||||||
|
|
||||||
/** Read boolean data from the SDA line */
|
/** Read boolean data from the SDA line */
|
||||||
bool readSDA() const { return jpee_mdat && jpee_sdat; }
|
bool readSDA() const { return jpee_mdat && jpee_sdat; }
|
||||||
|
|
|
@ -64,8 +64,8 @@ FilesystemNodePOSIX::FilesystemNodePOSIX(const string& path, bool verify)
|
||||||
// Expand '~' to the HOME environment variable
|
// Expand '~' to the HOME environment variable
|
||||||
if(_path[0] == '~')
|
if(_path[0] == '~')
|
||||||
{
|
{
|
||||||
const char* home = getenv("HOME");
|
string home = BSPF::getenv("HOME");
|
||||||
if(home != nullptr)
|
if(home != EmptyString)
|
||||||
_path.replace(0, 1, home);
|
_path.replace(0, 1, home);
|
||||||
}
|
}
|
||||||
// Get absolute path (only used for relative directories)
|
// Get absolute path (only used for relative directories)
|
||||||
|
@ -86,11 +86,11 @@ FilesystemNodePOSIX::FilesystemNodePOSIX(const string& path, bool verify)
|
||||||
string FilesystemNodePOSIX::getShortPath() const
|
string FilesystemNodePOSIX::getShortPath() const
|
||||||
{
|
{
|
||||||
// If the path starts with the home directory, replace it with '~'
|
// If the path starts with the home directory, replace it with '~'
|
||||||
const char* home = getenv("HOME");
|
string home = BSPF::getenv("HOME");
|
||||||
if(home != nullptr && BSPF::startsWithIgnoreCase(_path, home))
|
if(home != EmptyString && BSPF::startsWithIgnoreCase(_path, home))
|
||||||
{
|
{
|
||||||
string path = "~";
|
string path = "~";
|
||||||
const char* offset = _path.c_str() + strlen(home);
|
const char* offset = _path.c_str() + home.size();
|
||||||
if(*offset != '/') path += "/";
|
if(*offset != '/') path += "/";
|
||||||
path += offset;
|
path += offset;
|
||||||
return path;
|
return path;
|
||||||
|
|
|
@ -27,9 +27,9 @@ void OSystemUNIX::getBaseDirAndConfig(string& basedir, string& cfgfile,
|
||||||
bool useappdir, const string& usedir)
|
bool useappdir, const string& usedir)
|
||||||
{
|
{
|
||||||
// Use XDG_CONFIG_HOME if defined, otherwise use the default
|
// Use XDG_CONFIG_HOME if defined, otherwise use the default
|
||||||
const char* configDir = getenv("XDG_CONFIG_HOME");
|
string configDir = BSPF::getenv("XDG_CONFIG_HOME");
|
||||||
if(configDir == nullptr) configDir = "~/.config";
|
if(configDir == EmptyString) configDir = "~/.config";
|
||||||
basedir = string(configDir) + "/stella";
|
basedir = configDir + "/stella";
|
||||||
savedir = loaddir = "~/";
|
savedir = loaddir = "~/";
|
||||||
|
|
||||||
// Check to see if basedir overrides are active
|
// Check to see if basedir overrides are active
|
||||||
|
|
Loading…
Reference in New Issue