Private
Public Access
2
0

uart.hpp: trust c_str() instead of making copies

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2015-06-01 09:32:14 +01:00
parent 8493ed4239
commit ea71308702

View File

@@ -64,9 +64,7 @@ class Uart
*/ */
Uart(std::string path) Uart(std::string path)
{ {
char *p = new char[path.length() + 1]; m_uart = mraa_uart_init_raw(path.c_str());
std::strcpy(p, path.c_str());
m_uart = mraa_uart_init_raw(p);
if (m_uart == NULL) { if (m_uart == NULL) {
throw std::invalid_argument("Error initialising UART"); throw std::invalid_argument("Error initialising UART");
@@ -124,9 +122,8 @@ class Uart
int int
write(std::string data) write(std::string data)
{ {
char *d = new char[data.length() + 1]; // this is data.length() not +1 because we want to avoid the '\0' char
std::strcpy(d, data.c_str()); return mraa_uart_write(m_uart, data.c_str(), (data.length()));
return mraa_uart_write(m_uart, d, (data.length() + 1));
} }
/** /**