uart_ow.hpp: Correct a logic bug, and 2 questionable uses of c_str()
The command() function had a logic error that caused a command to be broadcast to all devices on the DS OW bus when a proper ID was specified. This should only be done when NO ID is specified. This fixes UPM issue #502. In addition, there were two cases where the C++ string accessor method .c_str() was used when .data() should be used instead. This worked anyway (accidentally), but is improper since the strings can have embedded 0 bytes. Signed-off-by: Jon Trulson <jtrulson@ics.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
committed by
Brendan Le Foll
parent
3bd590c18c
commit
c3332f5542
@@ -233,7 +233,7 @@ class UartOW
|
||||
mraa::Result
|
||||
command(uint8_t command, std::string id)
|
||||
{
|
||||
if (id.empty() == 0)
|
||||
if (id.empty())
|
||||
return (mraa::Result) mraa_uart_ow_command(m_uart, command, NULL);
|
||||
else {
|
||||
if (id.size() != 8) {
|
||||
@@ -241,7 +241,7 @@ class UartOW
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": id must be 8 bytes only");
|
||||
}
|
||||
return (mraa::Result) mraa_uart_ow_command(m_uart, command, (uint8_t*) id.c_str());
|
||||
return (mraa::Result) mraa_uart_ow_command(m_uart, command, (uint8_t*) id.data());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,7 +268,7 @@ class UartOW
|
||||
uint8_t
|
||||
crc8(std::string buffer)
|
||||
{
|
||||
return mraa_uart_ow_crc8((uint8_t*) buffer.c_str(), buffer.size());
|
||||
return mraa_uart_ow_crc8((uint8_t*) buffer.data(), buffer.size());
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user