Fix coverity complaining about unrestricted use of getenv.

This commit is contained in:
Stephen Anthony 2019-11-29 18:06:43 -03:30
parent 7cc49b4ff1
commit 8a0491f3d3
5 changed files with 24 additions and 12 deletions

View File

@ -245,6 +245,18 @@ namespace BSPF
#endif
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
#endif

View File

@ -156,7 +156,7 @@ void MT24LC256::systemReset()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void MT24LC256::eraseAll()
{
myData.fill(INIT_VALUE);
myData.fill(INITIAL_VALUE);
myDataChanged = true;
}
@ -167,7 +167,7 @@ void MT24LC256::eraseCurrent()
{
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;
}
}
@ -193,7 +193,7 @@ void MT24LC256::jpee_init()
jpee_smallmode = 0;
jpee_logmode = -1;
if(!myDataFileExists)
myData.fill(INIT_VALUE);
myData.fill(INITIAL_VALUE);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -51,7 +51,7 @@ class MT24LC256
static constexpr uInt32 PAGE_NUM = FLASH_SIZE / PAGE_SIZE;
// 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 */
bool readSDA() const { return jpee_mdat && jpee_sdat; }

View File

@ -64,8 +64,8 @@ FilesystemNodePOSIX::FilesystemNodePOSIX(const string& path, bool verify)
// Expand '~' to the HOME environment variable
if(_path[0] == '~')
{
const char* home = getenv("HOME");
if(home != nullptr)
string home = BSPF::getenv("HOME");
if(home != EmptyString)
_path.replace(0, 1, home);
}
// Get absolute path (only used for relative directories)
@ -86,11 +86,11 @@ FilesystemNodePOSIX::FilesystemNodePOSIX(const string& path, bool verify)
string FilesystemNodePOSIX::getShortPath() const
{
// If the path starts with the home directory, replace it with '~'
const char* home = getenv("HOME");
if(home != nullptr && BSPF::startsWithIgnoreCase(_path, home))
string home = BSPF::getenv("HOME");
if(home != EmptyString && BSPF::startsWithIgnoreCase(_path, home))
{
string path = "~";
const char* offset = _path.c_str() + strlen(home);
const char* offset = _path.c_str() + home.size();
if(*offset != '/') path += "/";
path += offset;
return path;

View File

@ -27,9 +27,9 @@ void OSystemUNIX::getBaseDirAndConfig(string& basedir, string& cfgfile,
bool useappdir, const string& usedir)
{
// Use XDG_CONFIG_HOME if defined, otherwise use the default
const char* configDir = getenv("XDG_CONFIG_HOME");
if(configDir == nullptr) configDir = "~/.config";
basedir = string(configDir) + "/stella";
string configDir = BSPF::getenv("XDG_CONFIG_HOME");
if(configDir == EmptyString) configDir = "~/.config";
basedir = configDir + "/stella";
savedir = loaddir = "~/";
// Check to see if basedir overrides are active