Skip to content

Commit

Permalink
lightware_lase_serial: fix pointer for enabling serial mode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MaEtUgR authored and bkueng committed Jun 21, 2023
1 parent fd267fb commit 18d89e4
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 18d89e4

Please sign in to comment.