@@ -151,7 +151,7 @@ public T ReadObject<T>(int offset) where T : struct
151151 offset = Offset + offset ;
152152 if ( offset + Marshal . SizeOf ( typeof ( T ) ) > data . Length )
153153 {
154- return default ( T ) ;
154+ return default ;
155155 }
156156
157157 var handle = GCHandle . Alloc ( data , GCHandleType . Pinned ) ;
@@ -173,7 +173,7 @@ public sbyte ReadInt8(int offset)
173173 offset = Offset + offset ;
174174 if ( offset + sizeof ( sbyte ) > data . Length )
175175 {
176- return default ( sbyte ) ;
176+ return default ;
177177 }
178178
179179 return ( sbyte ) data [ offset ] ;
@@ -189,7 +189,7 @@ public byte ReadUInt8(int offset)
189189 offset = Offset + offset ;
190190 if ( offset + sizeof ( byte ) > data . Length )
191191 {
192- return default ( byte ) ;
192+ return default ;
193193 }
194194
195195 return data [ offset ] ;
@@ -205,7 +205,7 @@ public short ReadInt16(int offset)
205205 offset = Offset + offset ;
206206 if ( offset + sizeof ( short ) > data . Length )
207207 {
208- return default ( short ) ;
208+ return default ;
209209 }
210210
211211 return BitConverter . ToInt16 ( data , offset ) ;
@@ -221,7 +221,7 @@ public ushort ReadUInt16(int offset)
221221 offset = Offset + offset ;
222222 if ( offset + sizeof ( ushort ) > data . Length )
223223 {
224- return default ( ushort ) ;
224+ return default ;
225225 }
226226
227227 return BitConverter . ToUInt16 ( data , offset ) ;
@@ -237,7 +237,7 @@ public int ReadInt32(int offset)
237237 offset = Offset + offset ;
238238 if ( offset + sizeof ( int ) > data . Length )
239239 {
240- return default ( int ) ;
240+ return default ;
241241 }
242242
243243 return BitConverter . ToInt32 ( data , offset ) ;
@@ -253,7 +253,7 @@ public uint ReadUInt32(int offset)
253253 offset = Offset + offset ;
254254 if ( offset + sizeof ( uint ) > data . Length )
255255 {
256- return default ( uint ) ;
256+ return default ;
257257 }
258258
259259 return BitConverter . ToUInt32 ( data , offset ) ;
@@ -269,7 +269,7 @@ public long ReadInt64(int offset)
269269 offset = Offset + offset ;
270270 if ( offset + sizeof ( long ) > data . Length )
271271 {
272- return default ( long ) ;
272+ return default ;
273273 }
274274
275275 return BitConverter . ToInt64 ( data , offset ) ;
@@ -285,7 +285,7 @@ public ulong ReadUInt64(int offset)
285285 offset = Offset + offset ;
286286 if ( offset + sizeof ( ulong ) > data . Length )
287287 {
288- return default ( ulong ) ;
288+ return default ;
289289 }
290290
291291 return BitConverter . ToUInt64 ( data , offset ) ;
@@ -301,7 +301,7 @@ public float ReadFloat(int offset)
301301 offset = Offset + offset ;
302302 if ( offset + sizeof ( float ) > data . Length )
303303 {
304- return default ( float ) ;
304+ return default ;
305305 }
306306
307307 return BitConverter . ToSingle ( data , offset ) ;
@@ -317,7 +317,7 @@ public double ReadDouble(int offset)
317317 offset = Offset + offset ;
318318 if ( offset + sizeof ( double ) > data . Length )
319319 {
320- return default ( double ) ;
320+ return default ;
321321 }
322322
323323 return BitConverter . ToDouble ( data , offset ) ;
@@ -373,7 +373,12 @@ public string ReadString(Encoding encoding, int offset, int length)
373373
374374 if ( Offset + offset + length > data . Length )
375375 {
376- length = data . Length - Offset - offset ;
376+ length = Math . Max ( data . Length - Offset - offset , 0 ) ;
377+ }
378+
379+ if ( length <= 0 )
380+ {
381+ return string . Empty ;
377382 }
378383
379384 var sb = new StringBuilder ( encoding . GetString ( data , Offset + offset , length ) ) ;
0 commit comments