mirror of
https://github.com/Ryujinx/Opentk.git
synced 2024-12-25 15:45:29 +00:00
Always validate parameters to ReadBit/EnableBit/DisableBit before using them.
This commit is contained in:
parent
76db3e188f
commit
821a8e1117
|
@ -39,7 +39,8 @@ namespace OpenTK.Input
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
// Allocate enough ints to store all keyboard keys
|
// Allocate enough ints to store all keyboard keys
|
||||||
const int NumInts = ((int)Key.LastKey + 31) / 32;
|
const int IntSize = sizeof(int);
|
||||||
|
const int NumInts = ((int)Key.LastKey + IntSize - 1) / IntSize;
|
||||||
// The following line triggers bogus CS0214 in gmcs 2.0.1, sigh...
|
// The following line triggers bogus CS0214 in gmcs 2.0.1, sigh...
|
||||||
unsafe fixed int Keys[NumInts];
|
unsafe fixed int Keys[NumInts];
|
||||||
|
|
||||||
|
@ -47,6 +48,24 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
#region Public Members
|
#region Public Members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a <see cref="System.Boolean"/> indicating whether the specified
|
||||||
|
/// <see cref="OpenTK.Input.Key"/> is pressed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="key">The <see cref="OpenTK.Input.Key"/> to check.</param>
|
||||||
|
/// <returns>True if key is pressed; false otherwise.</returns>
|
||||||
|
public bool this[Key key]
|
||||||
|
{
|
||||||
|
get { return IsKeyDown(key); }
|
||||||
|
internal set
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
EnableBit((int)key);
|
||||||
|
else
|
||||||
|
DisableBit((int)key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a <see cref="System.Boolean"/> indicating whether this key is down.
|
/// Gets a <see cref="System.Boolean"/> indicating whether this key is down.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -71,6 +90,8 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
internal bool ReadBit(int offset)
|
internal bool ReadBit(int offset)
|
||||||
{
|
{
|
||||||
|
ValidateOffset(offset);
|
||||||
|
|
||||||
int int_offset = offset / 32;
|
int int_offset = offset / 32;
|
||||||
int bit_offset = offset % 32;
|
int bit_offset = offset % 32;
|
||||||
unsafe
|
unsafe
|
||||||
|
@ -84,6 +105,8 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
internal void EnableBit(int offset)
|
internal void EnableBit(int offset)
|
||||||
{
|
{
|
||||||
|
ValidateOffset(offset);
|
||||||
|
|
||||||
int int_offset = offset / 32;
|
int int_offset = offset / 32;
|
||||||
int bit_offset = offset % 32;
|
int bit_offset = offset % 32;
|
||||||
unsafe
|
unsafe
|
||||||
|
@ -97,6 +120,8 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
internal void DisableBit(int offset)
|
internal void DisableBit(int offset)
|
||||||
{
|
{
|
||||||
|
ValidateOffset(offset);
|
||||||
|
|
||||||
int int_offset = offset / 32;
|
int int_offset = offset / 32;
|
||||||
int bit_offset = offset % 32;
|
int bit_offset = offset % 32;
|
||||||
unsafe
|
unsafe
|
||||||
|
@ -110,6 +135,16 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Private Members
|
||||||
|
|
||||||
|
static void ValidateOffset(int offset)
|
||||||
|
{
|
||||||
|
if (offset < 0 || offset >= NumInts * IntSize)
|
||||||
|
throw new ArgumentOutOfRangeException("offset");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region IEquatable<KeyboardState> Members
|
#region IEquatable<KeyboardState> Members
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -39,7 +39,8 @@ namespace OpenTK.Input
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
// Allocate enough ints to store all mouse buttons
|
// Allocate enough ints to store all mouse buttons
|
||||||
const int NumInts = ((int)MouseButton.LastButton + 31) / 32;
|
const int IntSize = sizeof(int);
|
||||||
|
const int NumInts = ((int)MouseButton.LastButton + IntSize - 1) / IntSize;
|
||||||
// The following line triggers bogus CS0214 in gmcs 2.0.1, sigh...
|
// The following line triggers bogus CS0214 in gmcs 2.0.1, sigh...
|
||||||
unsafe fixed int Buttons[NumInts];
|
unsafe fixed int Buttons[NumInts];
|
||||||
int x, y;
|
int x, y;
|
||||||
|
@ -49,6 +50,24 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
#region Public Members
|
#region Public Members
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a <see cref="System.Boolean"/> indicating whether the specified
|
||||||
|
/// <see cref="OpenTK.Input.MouseButton"/> is pressed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="button">The <see cref="OpenTK.Input.MouseButton"/> to check.</param>
|
||||||
|
/// <returns>True if key is pressed; false otherwise.</returns>
|
||||||
|
public bool this[MouseButton button]
|
||||||
|
{
|
||||||
|
get { return IsButtonDown(button); }
|
||||||
|
internal set
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
EnableBit((int)button);
|
||||||
|
else
|
||||||
|
DisableBit((int)button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a <see cref="System.Boolean"/> indicating whether this button is down.
|
/// Gets a <see cref="System.Boolean"/> indicating whether this button is down.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -106,19 +125,6 @@ namespace OpenTK.Input
|
||||||
internal set { y = value; }
|
internal set { y = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a System.Boolean indicating the state of the specified MouseButton.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="button">The MouseButton to check.</param>
|
|
||||||
/// <returns>True if the MouseButton is pressed, false otherwise.</returns>
|
|
||||||
public bool this[MouseButton button]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return IsButtonDown(button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a <see cref="System.Boolean" indicating whether the left mouse button is pressed.
|
/// Gets a <see cref="System.Boolean" indicating whether the left mouse button is pressed.
|
||||||
/// This property is intended for XNA compatibility.
|
/// This property is intended for XNA compatibility.
|
||||||
|
@ -251,6 +257,8 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
internal bool ReadBit(int offset)
|
internal bool ReadBit(int offset)
|
||||||
{
|
{
|
||||||
|
ValidateOffset(offset);
|
||||||
|
|
||||||
int int_offset = offset / 32;
|
int int_offset = offset / 32;
|
||||||
int bit_offset = offset % 32;
|
int bit_offset = offset % 32;
|
||||||
unsafe
|
unsafe
|
||||||
|
@ -264,6 +272,8 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
internal void EnableBit(int offset)
|
internal void EnableBit(int offset)
|
||||||
{
|
{
|
||||||
|
ValidateOffset(offset);
|
||||||
|
|
||||||
int int_offset = offset / 32;
|
int int_offset = offset / 32;
|
||||||
int bit_offset = offset % 32;
|
int bit_offset = offset % 32;
|
||||||
unsafe
|
unsafe
|
||||||
|
@ -277,6 +287,8 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
internal void DisableBit(int offset)
|
internal void DisableBit(int offset)
|
||||||
{
|
{
|
||||||
|
ValidateOffset(offset);
|
||||||
|
|
||||||
int int_offset = offset / 32;
|
int int_offset = offset / 32;
|
||||||
int bit_offset = offset % 32;
|
int bit_offset = offset % 32;
|
||||||
unsafe
|
unsafe
|
||||||
|
@ -290,6 +302,16 @@ namespace OpenTK.Input
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Private Members
|
||||||
|
|
||||||
|
static void ValidateOffset(int offset)
|
||||||
|
{
|
||||||
|
if (offset < 0 || offset >= NumInts * IntSize)
|
||||||
|
throw new ArgumentOutOfRangeException("offset");
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region IEquatable<MouseState> Members
|
#region IEquatable<MouseState> Members
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in a new issue