Skip to content

Commit

Permalink
Add check if length of buffer is good
Browse files Browse the repository at this point in the history
  • Loading branch information
frenzibyte authored Dec 25, 2017
1 parent b836eac commit ad2fe85
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions source/Cosmos.Core/MemoryBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,36 +106,60 @@ public void MoveUp(UInt32 aDest, UInt32 aSrc, UInt32 aCount)
#region ReadWrite
public unsafe void Read8(Byte[] aBuffer)
{
if(aBuffer.Length >= Size)
{
throw new Exception("Memory access violation");
}
for (int i = 0; i < aBuffer.Length; i++)
aBuffer[i] = (*(Byte*)(Base + i));
}

public unsafe void Write8(Byte[] aBuffer)
{
if(aBuffer.Length >= Size)
{
throw new Exception("Memory access violation");
}
for (int i = 0; i < aBuffer.Length; i++)
(*(Byte*)(Base + i)) = aBuffer[i];
}

public unsafe void Read16(UInt16[] aBuffer)
{
if(aBuffer.Length >= Size)
{
throw new Exception("Memory access violation");
}
for (int i = 0; i < aBuffer.Length; i++)
aBuffer[i] = (*(UInt16*)(Base + i));
}

public unsafe void Write16(UInt16[] aBuffer)
{
if(aBuffer.Length >= Size)
{
throw new Exception("Memory access violation");
}
for (int i = 0; i < aBuffer.Length; i++)
(*(UInt16*)(Base + i)) = aBuffer[i];
}

public unsafe void Read32(UInt32[] aBuffer)
{
if(aBuffer.Length >= Size)
{
throw new Exception("Memory access violation");
}
for (int i = 0; i < aBuffer.Length; i++)
aBuffer[i] = (*(UInt32*)(Base + i));
}

public unsafe void Write32(UInt32[] aBuffer)
{
if(aBuffer.Length >= Size)
{
throw new Exception("Memory access violation");
}
for (int i = 0; i < aBuffer.Length; i++)
(*(UInt32*)(Base + i)) = aBuffer[i];
}
Expand Down

0 comments on commit ad2fe85

Please sign in to comment.