diff --git a/components/drivers/serial/serial.c b/components/drivers/serial/serial.c index 1d78140015..0617652c04 100644 --- a/components/drivers/serial/serial.c +++ b/components/drivers/serial/serial.c @@ -1204,12 +1204,12 @@ static rt_err_t rt_serial_control(struct rt_device *dev, rt_memset(row_s,0,4); rt_memset(col_s,0,4); cnt1 = 0; - while(_tio_buf[cnt1] != ';' && cnt1 < _TIO_BUFLEN) + while(cnt1 < _TIO_BUFLEN && _tio_buf[cnt1] != ';') { cnt1++; } cnt2 = ++cnt1; - while(_tio_buf[cnt2] != ';' && cnt2 < _TIO_BUFLEN) + while(cnt2 < _TIO_BUFLEN && _tio_buf[cnt2] != ';') { cnt2++; } diff --git a/components/drivers/serial/serial_v2.c b/components/drivers/serial/serial_v2.c index 68f9068601..60d7a149fd 100644 --- a/components/drivers/serial/serial_v2.c +++ b/components/drivers/serial/serial_v2.c @@ -1316,12 +1316,12 @@ static rt_err_t rt_serial_control(struct rt_device *dev, rt_memset(row_s,0,4); rt_memset(col_s,0,4); cnt1 = 0; - while(_tio_buf[cnt1] != ';' && cnt1 < _TIO_BUFLEN) + while(cnt1 < _TIO_BUFLEN && _tio_buf[cnt1] != ';') { cnt1++; } cnt2 = ++cnt1; - while(_tio_buf[cnt2] != ';' && cnt2 < _TIO_BUFLEN) + while(cnt2 < _TIO_BUFLEN && _tio_buf[cnt2] != ';') { cnt2++; }