mhz16: Remove post-throw returns + small fixes

Removed the 'return false;' lines after throws since these are not
needed and are generally flagged by static analysis tools.  Also removed
a EOL spaces and added initializers for member variables at declaration
(since more than one constructor exists).

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck 2018-04-27 11:27:29 -07:00
parent dd73c4aa45
commit 17110d41d0
2 changed files with 13 additions and 25 deletions

View File

@ -41,7 +41,6 @@ MHZ16::MHZ16(int uart)
{ {
throw std::invalid_argument(std::string(__FUNCTION__) + throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_uart_init() failed"); ": mraa_uart_init() failed");
return;
} }
// This requires a recent MRAA (1/2015) // This requires a recent MRAA (1/2015)
@ -51,7 +50,6 @@ MHZ16::MHZ16(int uart)
{ {
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
": mraa_uart_get_dev_path() failed"); ": mraa_uart_get_dev_path() failed");
return;
} }
// now open the tty // now open the tty
@ -61,7 +59,6 @@ MHZ16::MHZ16(int uart)
": open of " + ": open of " +
string(devPath) + " failed: " + string(devPath) + " failed: " +
string(strerror(errno))); string(strerror(errno)));
return;
} }
} }
@ -73,7 +70,6 @@ MHZ16::MHZ16(const std::string& uart_raw)
{ {
throw std::invalid_argument(std::string(__FUNCTION__) + throw std::invalid_argument(std::string(__FUNCTION__) +
": mraa_uart_init_raw() failed"); ": mraa_uart_init_raw() failed");
return;
} }
// This requires a recent MRAA (1/2015) // This requires a recent MRAA (1/2015)
@ -83,7 +79,6 @@ MHZ16::MHZ16(const std::string& uart_raw)
{ {
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
": mraa_uart_get_dev_path() failed"); ": mraa_uart_get_dev_path() failed");
return;
} }
// now open the tty // now open the tty
@ -93,7 +88,6 @@ MHZ16::MHZ16(const std::string& uart_raw)
": open of " + ": open of " +
string(devPath) + " failed: " + string(devPath) + " failed: " +
string(strerror(errno))); string(strerror(errno)));
return;
} }
} }
@ -124,8 +118,8 @@ bool MHZ16::dataAvailable(unsigned int millis)
if (select(m_ttyFd + 1, &readfds, NULL, NULL, &timeout) > 0) if (select(m_ttyFd + 1, &readfds, NULL, NULL, &timeout) > 0)
return true; // data is ready return true; // data is ready
else
return false; return false;
} }
int MHZ16::readData(char *buffer, int len) int MHZ16::readData(char *buffer, int len)
@ -143,7 +137,6 @@ int MHZ16::readData(char *buffer, int len)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
": read() failed: " + ": read() failed: " +
string(strerror(errno))); string(strerror(errno)));
return rv;
} }
return rv; return rv;
@ -164,7 +157,6 @@ int MHZ16::writeData(char *buffer, int len)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
": write() failed: " + ": write() failed: " +
string(strerror(errno))); string(strerror(errno)));
return rv;
} }
tcdrain(m_ttyFd); tcdrain(m_ttyFd);
@ -196,7 +188,6 @@ bool MHZ16::setupTty(speed_t baud)
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
": tcsetattr() failed: " + ": tcsetattr() failed: " +
string(strerror(errno))); string(strerror(errno)));
return false;
} }
return true; return true;
@ -208,7 +199,6 @@ bool MHZ16::verifyPacket(uint8_t *pkt, int len)
{ {
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
": invalid packet header received"); ": invalid packet header received");
return false;
} }
return true; return true;
@ -227,7 +217,6 @@ bool MHZ16::getData()
{ {
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
": Timed out waiting for response"); ": Timed out waiting for response");
return false;
} }
// read the packet // read the packet
@ -238,7 +227,6 @@ bool MHZ16::getData()
{ {
throw std::runtime_error(std::string(__FUNCTION__) + throw std::runtime_error(std::string(__FUNCTION__) +
": Invalid packet size read"); ": Invalid packet size read");
return false;
} }
// will throw an exception if it fails // will throw an exception if it fails

View File

@ -170,9 +170,9 @@ namespace upm {
private: private:
mraa_uart_context m_uart; mraa_uart_context m_uart;
int m_ttyFd; int m_ttyFd = 0;
int gas; int gas = 0;
int temp; int temp = 0;
}; };
} }