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
- DataSourceListEditor.cs
- SiteMapNode.cs
- AutomationAttributeInfo.cs
- dtdvalidator.cs
- SemanticBasicElement.cs
- Solver.cs
- LineBreak.cs
- WithParamAction.cs
- ProviderException.cs
- ListDictionary.cs
- LoginView.cs
- CharStorage.cs
- TextChange.cs
- RoleManagerSection.cs
- NonVisualControlAttribute.cs
- RegexMatch.cs
- SerialPinChanges.cs
- DependencyProperty.cs
- Cursor.cs
- EFDataModelProvider.cs
- XmlText.cs
- RepeaterCommandEventArgs.cs
- ProtectedProviderSettings.cs
- RuntimeCompatibilityAttribute.cs
- TraceInternal.cs
- DeploymentExceptionMapper.cs
- BoundingRectTracker.cs
- ElementNotEnabledException.cs
- FixedSOMPage.cs
- XPathAxisIterator.cs
- AmbientLight.cs
- PenLineCapValidation.cs
- WorkflowInvoker.cs
- GreenMethods.cs
- ViewPort3D.cs
- RuleSettings.cs
- IgnoreFlushAndCloseStream.cs
- ComboBoxRenderer.cs
- DataGridViewColumnConverter.cs
- DecoderReplacementFallback.cs
- ScrollEventArgs.cs
- CreateParams.cs
- ScriptingJsonSerializationSection.cs
- LingerOption.cs
- RotateTransform.cs
- TransformerTypeCollection.cs
- mil_sdk_version.cs
- TypeUtil.cs
- BookmarkScope.cs
- IOThreadScheduler.cs
- MethodToken.cs
- SQLGuidStorage.cs
- FileFormatException.cs
- DynamicUpdateCommand.cs
- XmlSortKeyAccumulator.cs
- Attachment.cs
- Buffer.cs
- CurrencyWrapper.cs
- ResourceType.cs
- SqlFunctions.cs
- RootDesignerSerializerAttribute.cs
- XsdBuildProvider.cs
- ClosableStream.cs
- SafeEventLogWriteHandle.cs
- CustomSignedXml.cs
- CredentialCache.cs
- MasterPage.cs
- KeyedCollection.cs
- InputMethodStateChangeEventArgs.cs
- Material.cs
- ShaderEffect.cs
- GeneralTransform3DCollection.cs
- SoapProtocolImporter.cs
- BuildProviderCollection.cs
- StrokeFIndices.cs
- _SslSessionsCache.cs
- BindingListCollectionView.cs
- UshortList2.cs
- ContractTypeNameCollection.cs
- TreeViewItemAutomationPeer.cs
- GridViewDeleteEventArgs.cs
- RuntimeEnvironment.cs
- MeasureItemEvent.cs
- QuadraticBezierSegment.cs
- TypedTableBaseExtensions.cs
- MetadataPropertyAttribute.cs
- TextPointer.cs
- DesignTimeTemplateParser.cs
- HtmlMeta.cs
- NominalTypeEliminator.cs
- MergeFilterQuery.cs
- WindowsSysHeader.cs
- ScrollPattern.cs
- QilInvokeLateBound.cs
- XpsImage.cs
- ServiceHttpHandlerFactory.cs
- HttpListenerContext.cs
- FixedNode.cs
- LinearQuaternionKeyFrame.cs
- SR.cs