summaryrefslogtreecommitdiffstats
path: root/simulator
diff options
context:
space:
mode:
authorEvan Lojewski <github@meklort.com>2020-04-11 20:34:40 -0600
committerGitHub <noreply@github.com>2020-04-11 20:34:40 -0600
commita985bfd6cdbe977e02c72de85f958e74ddf372e7 (patch)
tree49fca1761d01f1ed258738b8772df7684e4338e6 /simulator
parentdc9705b4c65aa6b059a2f6beaf4d370620e583b7 (diff)
downloadbcm5719-ortega-a985bfd6cdbe977e02c72de85f958e74ddf372e7.tar.gz
bcm5719-ortega-a985bfd6cdbe977e02c72de85f958e74ddf372e7.zip
coverity: Fix issues found with coverity (#78)
Diffstat (limited to 'simulator')
-rw-r--r--simulator/HAL.cpp25
-rw-r--r--simulator/include/CXXRegister.h14
2 files changed, 32 insertions, 7 deletions
diff --git a/simulator/HAL.cpp b/simulator/HAL.cpp
index e6febb7..aea268b 100644
--- a/simulator/HAL.cpp
+++ b/simulator/HAL.cpp
@@ -184,7 +184,7 @@ static char* locate_pci_path(int wanted_function)
{
pci_config_t config;
- if (fread(&config, sizeof(config), 1, pConfigFile))
+ if (1 == fread(&config, sizeof(config), 1, pConfigFile))
{
if (is_supported(config.vendor_id, config.device_id))
{
@@ -240,8 +240,11 @@ bool initHAL(const char *pci_path, int wanted_function)
}
pci_config_t config;
+ size_t read_count = fread(&config, sizeof(config), 1, pConfigFile);
- if (fread(&config, sizeof(config), 1, pConfigFile))
+ fclose(pConfigFile);
+
+ if (1 == read_count)
{
if (is_supported(config.vendor_id, config.device_id))
{
@@ -255,7 +258,7 @@ bool initHAL(const char *pci_path, int wanted_function)
if ((memfd = open(pBARPath, O_RDWR | O_SYNC)) < 0)
{
printf("Error opening %s file. \n", pBARPath);
- close(memfd);
+
if(located_pci_path)
{
free(located_pci_path);
@@ -274,6 +277,9 @@ bool initHAL(const char *pci_path, int wanted_function)
{
free(located_pci_path);
}
+
+ close(memfd);
+
return false;
}
@@ -287,6 +293,9 @@ bool initHAL(const char *pci_path, int wanted_function)
{
free(located_pci_path);
}
+
+ close(memfd);
+
return false;
}
@@ -297,6 +306,16 @@ bool initHAL(const char *pci_path, int wanted_function)
}
}
}
+ else
+ {
+ // Unable to read configuration. Exit.
+ if(located_pci_path)
+ {
+ free(located_pci_path);
+ }
+
+ return false;
+ }
if(located_pci_path)
{
diff --git a/simulator/include/CXXRegister.h b/simulator/include/CXXRegister.h
index dd5c1d1..83ab5d8 100644
--- a/simulator/include/CXXRegister.h
+++ b/simulator/include/CXXRegister.h
@@ -134,13 +134,17 @@ public:
{
const char* name = mName;
char addr_str[16];
+
if(!name)
{
snprintf(addr_str, sizeof(addr_str), "0x%X", mComponentOffset);
name = addr_str;
}
+
unsigned int masked = (value & mMask) >> mBitPosition;
const char* enumstr = getEnum(masked);
+ std::ios::fmtflags fmt(std::cout.flags());
+
if (indent)
{
std::cout << std::right << std::setw(35) << name << ": 0x"
@@ -152,10 +156,14 @@ public:
<< std::left << std::setw(36) << name << " 0x"
<< std::hex << masked;
}
+
+ std::cout.flags(fmt);
+
if(enumstr)
{
std::cout << " (" << enumstr << ")";
}
+
std::cout << std::endl;
}
@@ -359,15 +367,13 @@ private:
}
public:
- CXXRegister() : CXXRegisterBase(OFFSET, WIDTH)
+ CXXRegister() : CXXRegisterBase(OFFSET, WIDTH), mValue(0), mTempValue(0)
{
- mValue = 0;
}
- CXXRegister(T val) : CXXRegisterBase(OFFSET, WIDTH)
+ CXXRegister(T val) : CXXRegisterBase(OFFSET, WIDTH), mValue(val), mTempValue(0)
{
// Manually instantiated. FIXME.
- mValue = val;
}
void installReadCallback(callback_t callback, void *args)
OpenPOWER on IntegriCloud