From c3332f554273b6b24c3c65b0542975790ac976a8 Mon Sep 17 00:00:00 2001 From: Jon Trulson Date: Tue, 17 Jan 2017 17:01:52 -0700 Subject: [PATCH] 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 Signed-off-by: Brendan Le Foll --- api/mraa/uart_ow.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/mraa/uart_ow.hpp b/api/mraa/uart_ow.hpp index d20f87e..84297e7 100644 --- a/api/mraa/uart_ow.hpp +++ b/api/mraa/uart_ow.hpp @@ -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: