From 7f2b6b1afb1ce3cee060c5bf210268198d9badac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Sinan=20A=C4=9Facan?= Date: Tue, 24 Oct 2023 14:40:41 +0200 Subject: [PATCH] Add a guard for empty splices --- protobuf/lib/src/protobuf/coded_buffer_writer.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/protobuf/lib/src/protobuf/coded_buffer_writer.dart b/protobuf/lib/src/protobuf/coded_buffer_writer.dart index 1c5c2b1a0..6307d0dbb 100644 --- a/protobuf/lib/src/protobuf/coded_buffer_writer.dart +++ b/protobuf/lib/src/protobuf/coded_buffer_writer.dart @@ -223,9 +223,11 @@ class CodedBufferWriter { /// Add TypedData splice - these bytes would be directly copied into the /// output buffer by [writeTo]. void writeRawBytes(TypedData value) { + final length = value.lengthInBytes; + if (length == 0) return; _commitSplice(); _splices.add(value); - _bytesTotal += value.lengthInBytes; + _bytesTotal += length; } /// Start writing a length-delimited data.