Skip to content

Commit 65e9086

Browse files
committed
Fix negative values crashes
Fixes #20
1 parent fc8b346 commit 65e9086

File tree

4 files changed

+193
-55
lines changed

4 files changed

+193
-55
lines changed

Source/EndianBinaryIO.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<PackageId>EndianBinaryIO</PackageId>
1010
<Product>EndianBinaryIO</Product>
1111
<AssemblyName>EndianBinaryIO</AssemblyName>
12-
<Version>1.1.0.0</Version>
12+
<Version>1.1.1.0</Version>
1313
<RepositoryUrl>https://github.com/Kermalis/EndianBinaryIO</RepositoryUrl>
1414
<RepositoryType>git</RepositoryType>
1515
<NoWarn />

Source/EndianBinaryReader.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ public short ReadInt16(long offset)
421421
public short[] ReadInt16s(int count)
422422
{
423423
ReadBytesIntoBuffer(count * 2);
424-
return EndianBitConverter.BytesToInt16s<short>(_buffer, 0, count, Endianness);
424+
return EndianBitConverter.BytesToInt16s(_buffer, 0, count, Endianness);
425425
}
426426
public short[] ReadInt16s(int count, long offset)
427427
{
@@ -441,7 +441,7 @@ public ushort ReadUInt16(long offset)
441441
public ushort[] ReadUInt16s(int count)
442442
{
443443
ReadBytesIntoBuffer(count * 2);
444-
return EndianBitConverter.BytesToInt16s<ushort>(_buffer, 0, count, Endianness);
444+
return EndianBitConverter.BytesToUInt16s(_buffer, 0, count, Endianness);
445445
}
446446
public ushort[] ReadUInt16s(int count, long offset)
447447
{
@@ -461,7 +461,7 @@ public int ReadInt32(long offset)
461461
public int[] ReadInt32s(int count)
462462
{
463463
ReadBytesIntoBuffer(count * 4);
464-
return EndianBitConverter.BytesToInt32s<int>(_buffer, 0, count, Endianness);
464+
return EndianBitConverter.BytesToInt32s(_buffer, 0, count, Endianness);
465465
}
466466
public int[] ReadInt32s(int count, long offset)
467467
{
@@ -481,7 +481,7 @@ public uint ReadUInt32(long offset)
481481
public uint[] ReadUInt32s(int count)
482482
{
483483
ReadBytesIntoBuffer(count * 4);
484-
return EndianBitConverter.BytesToInt32s<uint>(_buffer, 0, count, Endianness);
484+
return EndianBitConverter.BytesToUInt32s(_buffer, 0, count, Endianness);
485485
}
486486
public uint[] ReadUInt32s(int count, long offset)
487487
{
@@ -501,7 +501,7 @@ public long ReadInt64(long offset)
501501
public long[] ReadInt64s(int count)
502502
{
503503
ReadBytesIntoBuffer(count * 8);
504-
return EndianBitConverter.BytesToInt64s<long>(_buffer, 0, count, Endianness);
504+
return EndianBitConverter.BytesToInt64s(_buffer, 0, count, Endianness);
505505
}
506506
public long[] ReadInt64s(int count, long offset)
507507
{
@@ -521,7 +521,7 @@ public ulong ReadUInt64(long offset)
521521
public ulong[] ReadUInt64s(int count)
522522
{
523523
ReadBytesIntoBuffer(count * 8);
524-
return EndianBitConverter.BytesToInt64s<ulong>(_buffer, 0, count, Endianness);
524+
return EndianBitConverter.BytesToUInt64s(_buffer, 0, count, Endianness);
525525
}
526526
public ulong[] ReadUInt64s(int count, long offset)
527527
{
@@ -541,7 +541,7 @@ public float ReadSingle(long offset)
541541
public float[] ReadSingles(int count)
542542
{
543543
ReadBytesIntoBuffer(count * 4);
544-
return EndianBitConverter.BytesToSingles<float>(_buffer, 0, count, Endianness);
544+
return EndianBitConverter.BytesToSingles(_buffer, 0, count, Endianness);
545545
}
546546
public float[] ReadSingles(int count, long offset)
547547
{
@@ -561,7 +561,7 @@ public double ReadDouble(long offset)
561561
public double[] ReadDoubles(int count)
562562
{
563563
ReadBytesIntoBuffer(count * 8);
564-
return EndianBitConverter.BytesToDoubles<double>(_buffer, 0, count, Endianness);
564+
return EndianBitConverter.BytesToDoubles(_buffer, 0, count, Endianness);
565565
}
566566
public double[] ReadDoubles(int count, long offset)
567567
{
@@ -581,7 +581,7 @@ public decimal ReadDecimal(long offset)
581581
public decimal[] ReadDecimals(int count)
582582
{
583583
ReadBytesIntoBuffer(count * 16);
584-
return EndianBitConverter.BytesToDecimals<decimal>(_buffer, 0, count, Endianness);
584+
return EndianBitConverter.BytesToDecimals(_buffer, 0, count, Endianness);
585585
}
586586
public decimal[] ReadDecimals(int count, long offset)
587587
{

Source/EndianBinaryWriter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public void Write(ushort[] value, long offset)
450450
}
451451
public void Write(ushort[] value, int startIndex, int count)
452452
{
453-
_buffer = EndianBitConverter.Int16sToBytes(value, startIndex, count, Endianness);
453+
_buffer = EndianBitConverter.UInt16sToBytes(value, startIndex, count, Endianness);
454454
WriteBytesFromBuffer(count * 2);
455455
}
456456
public void Write(ushort[] value, int startIndex, int count, long offset)
@@ -508,7 +508,7 @@ public void Write(uint[] value, long offset)
508508
}
509509
public void Write(uint[] value, int startIndex, int count)
510510
{
511-
_buffer = EndianBitConverter.Int32sToBytes(value, startIndex, count, Endianness);
511+
_buffer = EndianBitConverter.UInt32sToBytes(value, startIndex, count, Endianness);
512512
WriteBytesFromBuffer(count * 4);
513513
}
514514
public void Write(uint[] value, int startIndex, int count, long offset)
@@ -566,7 +566,7 @@ public void Write(ulong[] value, long offset)
566566
}
567567
public void Write(ulong[] value, int startIndex, int count)
568568
{
569-
_buffer = EndianBitConverter.Int64sToBytes(value, startIndex, count, Endianness);
569+
_buffer = EndianBitConverter.UInt64sToBytes(value, startIndex, count, Endianness);
570570
WriteBytesFromBuffer(count * 8);
571571
}
572572
public void Write(ulong[] value, int startIndex, int count, long offset)

0 commit comments

Comments
 (0)