RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Avoid "unsafe" operations in BinaryFileWriter

Lichtblitz

Sorceror
Avoid "unsafe" operations in BinaryFileWriter

Original code is commented out:

PHP:
		public /*unsafe*/ override void Write( double value )
		{
			// May dupe; MODIFIED: new implementation since operation was unsafe

			byte[] eightBytes = System.BitConverter.GetBytes( value );
			for ( int i = 0; i < 8; i++ )
			{
				Write( eightBytes[i] );
			}

			/*
			if( (m_Index + 8) > m_Buffer.Length )
				Flush();

			fixed( byte* pBuffer = m_Buffer )
				*((double*)(pBuffer + m_Index)) = value;

			m_Index += 8;
			 */
		}

		public /*unsafe*/ override void Write( float value )
		{
			// May dupe; MODIFIED: new implementation since operation was unsafe

			byte[] fourBytes = System.BitConverter.GetBytes( value );
			for ( int i = 0; i < 4; i++ )
			{
				Write( fourBytes[i] );
			}

			/*
			if ( (m_Index + 4) > BufferSize )
				Flush();

			fixed ( byte* pBuffer = m_Buffer )
				*((float*)(&pBuffer[m_Index])) = value;

			m_Index += 4;
			 */
		}
 
Top