From a4455a91a2928be5a223d1ef8a8d16b95211ea72 Mon Sep 17 00:00:00 2001 From: AnAx Date: Sat, 25 Nov 2023 18:39:58 +0000 Subject: [PATCH] Checking serial port for NULL and 0 --- microbit-serial.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/microbit-serial.cpp b/microbit-serial.cpp index 54cd9a7..72412cd 100644 --- a/microbit-serial.cpp +++ b/microbit-serial.cpp @@ -6,8 +6,12 @@ MicroBitSerial::~MicroBitSerial(void){ this->end(); } const int MicroBitSerial::init(const char* serial_port_string) { - this->serial_port = open(serial_port_string, O_RDWR); + if((serial_port_string == NULL) || (strlen(serial_port_string) == 0) ) { + serial_port_string = this->SERIAL_PORT_DEFAULT_STRING; + } + this->serial_port = open(serial_port_string, O_RDWR); + if(this->serial_port < 1) { return this->ERR_SERIAL_OPEN; }