Skip to content

Commit

Permalink
Checking serial port for NULL and 0
Browse files Browse the repository at this point in the history
  • Loading branch information
AnAxNu committed Nov 25, 2023
1 parent 3f44c4b commit a4455a9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion microbit-serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit a4455a9

Please sign in to comment.