Skip to content

Commit 8605649

Browse files
committed
fix: Ensure timeout_ms is non-negative in serial read and write functions
- Added a check to set timeout_ms to 0 if it is negative in both serial_read.cpp and serial_write.cpp to prevent potential issues with negative timeout values.
1 parent cc22b2a commit 8605649

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/serial_read.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ extern "C"
2424
"Invalid handle");
2525
}
2626

27+
if (timeout_ms < 0)
28+
{
29+
timeout_ms = 0;
30+
}
31+
2732
const int fd = static_cast<int>(handle);
2833
auto *buf = static_cast<unsigned char *>(buffer);
2934

src/serial_write.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ extern "C"
2727
"Invalid handle");
2828
}
2929

30+
if (timeout_ms < 0)
31+
{
32+
timeout_ms = 0;
33+
}
34+
3035
const int fd = static_cast<int>(handle);
3136

3237
ssize_t bytes_written = ::write(fd, buffer, buffer_size);

0 commit comments

Comments
 (0)