Skip to content

Commit

Permalink
uart_ow.hpp: Correct a logic bug, and 2 questionable uses of c_str()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
jontrulson authored and arfoll committed Jan 19, 2017
1 parent 3bd590c commit c3332f5
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions api/mraa/uart_ow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,15 @@ 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) {
// Only 8 byte romcodes are legal.
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());
}
}

Expand All @@ -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:
Expand Down

0 comments on commit c3332f5

Please sign in to comment.