From ea7130870230e4c6741e3c480aba2b4e11452c11 Mon Sep 17 00:00:00 2001 From: Brendan Le Foll Date: Mon, 1 Jun 2015 09:32:14 +0100 Subject: [PATCH] uart.hpp: trust c_str() instead of making copies Signed-off-by: Brendan Le Foll --- api/mraa/uart.hpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/api/mraa/uart.hpp b/api/mraa/uart.hpp index f8788ef..5a92fb3 100644 --- a/api/mraa/uart.hpp +++ b/api/mraa/uart.hpp @@ -64,9 +64,7 @@ class Uart */ Uart(std::string path) { - char *p = new char[path.length() + 1]; - std::strcpy(p, path.c_str()); - m_uart = mraa_uart_init_raw(p); + m_uart = mraa_uart_init_raw(path.c_str()); if (m_uart == NULL) { throw std::invalid_argument("Error initialising UART"); @@ -124,9 +122,8 @@ class Uart int write(std::string data) { - char *d = new char[data.length() + 1]; - std::strcpy(d, data.c_str()); - return mraa_uart_write(m_uart, d, (data.length() + 1)); + // this is data.length() not +1 because we want to avoid the '\0' char + return mraa_uart_write(m_uart, data.c_str(), (data.length())); } /**