libserialport.dart icon indicating copy to clipboard operation
libserialport.dart copied to clipboard

read throws exception when sp_nonblocking_read returns negative number in case of error

Open cabbi opened this issue 1 year ago • 3 comments

This piece of code in util.dart does not handle error code in case sp_nonblocking_read fails

  static Uint8List read(int bytes, UtilFunc<ffi.Uint8> readFunc) {
    return ffi.using((arena) {
      final ptr = arena<ffi.Uint8>(bytes);
      final len = call(() => readFunc(ptr));
      return Uint8List.fromList(ptr.asTypedList(len));
    });
  }

This will fix the error:

      return Uint8List.fromList(ptr.asTypedList(len < 0 ? 0 : len));

cabbi avatar Jan 30 '24 20:01 cabbi