Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / UnSafeCharBuffer.cs / 1305376 / UnSafeCharBuffer.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: UnSafeBuffer ** ** Purpose: A class to detect incorrect usage of UnSafeBuffer ** ** ===========================================================*/ namespace System { using System.Diagnostics; using System.Diagnostics.Contracts; unsafe internal struct UnSafeCharBuffer{ char * m_buffer; int m_totalSize; int m_length; [System.Security.SecurityCritical] // auto-generated public UnSafeCharBuffer( char *buffer, int bufferSize) { Contract.Assert( buffer != null, "buffer pointer can't be null." ); Contract.Assert( bufferSize >= 0, "buffer size can't be negative." ); m_buffer = buffer; m_totalSize = bufferSize; m_length = 0; } [System.Security.SecuritySafeCritical] // auto-generated public void AppendString(string stringToAppend) { if( String.IsNullOrEmpty( stringToAppend ) ) { return; } if ( (m_totalSize - m_length) < stringToAppend.Length ) { throw new IndexOutOfRangeException(); } fixed( char* pointerToString = stringToAppend ) { Buffer.memcpyimpl( (byte *) pointerToString, (byte*) (m_buffer + m_length), stringToAppend.Length * sizeof(char)); } m_length += stringToAppend.Length; Contract.Assert(m_length <= m_totalSize, "Buffer has been overflowed!"); } public int Length { get { return m_length; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: UnSafeBuffer ** ** Purpose: A class to detect incorrect usage of UnSafeBuffer ** ** ===========================================================*/ namespace System { using System.Diagnostics; using System.Diagnostics.Contracts; unsafe internal struct UnSafeCharBuffer{ char * m_buffer; int m_totalSize; int m_length; [System.Security.SecurityCritical] // auto-generated public UnSafeCharBuffer( char *buffer, int bufferSize) { Contract.Assert( buffer != null, "buffer pointer can't be null." ); Contract.Assert( bufferSize >= 0, "buffer size can't be negative." ); m_buffer = buffer; m_totalSize = bufferSize; m_length = 0; } [System.Security.SecuritySafeCritical] // auto-generated public void AppendString(string stringToAppend) { if( String.IsNullOrEmpty( stringToAppend ) ) { return; } if ( (m_totalSize - m_length) < stringToAppend.Length ) { throw new IndexOutOfRangeException(); } fixed( char* pointerToString = stringToAppend ) { Buffer.memcpyimpl( (byte *) pointerToString, (byte*) (m_buffer + m_length), stringToAppend.Length * sizeof(char)); } m_length += stringToAppend.Length; Contract.Assert(m_length <= m_totalSize, "Buffer has been overflowed!"); } public int Length { get { return m_length; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ParallelTimeline.cs
- ScrollPattern.cs
- HitTestFilterBehavior.cs
- ClientApiGenerator.cs
- RelationshipManager.cs
- XmlDesigner.cs
- TransformerInfoCollection.cs
- ChannelCacheSettings.cs
- OdbcConnectionOpen.cs
- APCustomTypeDescriptor.cs
- XmlSchemas.cs
- Base64WriteStateInfo.cs
- SendMailErrorEventArgs.cs
- DataGridViewCellValidatingEventArgs.cs
- GeometryGroup.cs
- PhysicalFontFamily.cs
- SerializationException.cs
- CursorConverter.cs
- ZipIOExtraFieldZip64Element.cs
- FixedTextContainer.cs
- GenericEnumConverter.cs
- ElementAction.cs
- OverrideMode.cs
- PhysicalOps.cs
- EncoderNLS.cs
- Debugger.cs
- AppLevelCompilationSectionCache.cs
- PageParser.cs
- SyntaxCheck.cs
- Monitor.cs
- PersonalizableAttribute.cs
- KerberosSecurityTokenProvider.cs
- BindStream.cs
- String.cs
- GetPolicyDetailsRequest.cs
- CodeGenerator.cs
- NameValuePermission.cs
- WpfXamlLoader.cs
- ConfigXmlAttribute.cs
- XPathNodePointer.cs
- ComponentEditorForm.cs
- PerformanceCountersElement.cs
- DataGridRow.cs
- BindingMemberInfo.cs
- cache.cs
- PersistenceTypeAttribute.cs
- PathSegment.cs
- TypeDescriptor.cs
- EditBehavior.cs
- RadialGradientBrush.cs
- GiveFeedbackEventArgs.cs
- DateTimeUtil.cs
- Matrix3DConverter.cs
- RuntimeIdentifierPropertyAttribute.cs
- TogglePatternIdentifiers.cs
- CopyNodeSetAction.cs
- MultipleViewPattern.cs
- ILGen.cs
- CodeLinePragma.cs
- BamlRecordReader.cs
- DataAdapter.cs
- ColorDialog.cs
- infer.cs
- UnhandledExceptionEventArgs.cs
- ConfigXmlCDataSection.cs
- EntitySet.cs
- PublisherIdentityPermission.cs
- InterleavedZipPartStream.cs
- ExcludePathInfo.cs
- LinkedResource.cs
- SelectManyQueryOperator.cs
- Flattener.cs
- Asn1IntegerConverter.cs
- TextBox.cs
- AliasGenerator.cs
- MimeTextImporter.cs
- HttpBindingExtension.cs
- DBCommandBuilder.cs
- XmlUtilWriter.cs
- StringDictionary.cs
- PropertyDescriptorGridEntry.cs
- LogSwitch.cs
- RichTextBox.cs
- HotSpot.cs
- Pool.cs
- HttpApplicationFactory.cs
- TextTreeUndoUnit.cs
- EncryptedPackage.cs
- XPathParser.cs
- StateChangeEvent.cs
- GenericTypeParameterBuilder.cs
- ProviderConnectionPointCollection.cs
- PopOutPanel.cs
- BaseInfoTable.cs
- RemotingServices.cs
- FrameworkTemplate.cs
- TableMethodGenerator.cs
- GenericTextProperties.cs
- InputLangChangeRequestEvent.cs
- ValidationManager.cs