From 18d89e4bc15ba0fc0214e44bb57ad409d2d20b7a Mon Sep 17 00:00:00 2001 From: Matthias Grob Date: Wed, 21 Jun 2023 14:27:30 +0200 Subject: [PATCH] lightware_lase_serial: fix pointer for enabling serial mode const char *data = "www\r\n"; Defines a cstring of 6 bytes: 'w', 'w', 'w', '\r', '\n', '\0' type of data: char const* type of &data: char const** So when we call write(_fd, &data, strlen(data)); then strlen(data) == 5 and we send the 4 byte memory address of data + some additional random byte. Correct is write(_fd, data, strlen(data)); where char const* gets casted to const void * and we pass the pointer to the content of data. The fundamental problem here is write() not being typesafe. --- .../lightware_laser_serial/lightware_laser_serial.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/distance_sensor/lightware_laser_serial/lightware_laser_serial.cpp b/src/drivers/distance_sensor/lightware_laser_serial/lightware_laser_serial.cpp index de418c69d7..f27636657f 100644 --- a/src/drivers/distance_sensor/lightware_laser_serial/lightware_laser_serial.cpp +++ b/src/drivers/distance_sensor/lightware_laser_serial/lightware_laser_serial.cpp @@ -308,7 +308,7 @@ void LightwareLaserSerial::Run() // LW20: Enable serial mode by sending some characters if (hw_model == 8) { const char *data = "www\r\n"; - (void)!::write(_fd, &data, strlen(data)); + (void)!::write(_fd, data, strlen(data)); } }