@@ -63,11 +63,7 @@ async Task<bool> StepByteOrderMarkAsync (CancellationToken cancellationToken)
63
63
return false ;
64
64
}
65
65
66
- unsafe {
67
- fixed ( byte * inbuf = input ) {
68
- complete = StepByteOrderMark ( inbuf , ref bomIndex ) ;
69
- }
70
- }
66
+ complete = StepByteOrderMark ( ref bomIndex ) ;
71
67
} while ( ! complete && inputIndex == inputEnd ) ;
72
68
73
69
return complete ;
@@ -89,11 +85,7 @@ async Task StepMboxMarkerAsync (CancellationToken cancellationToken)
89
85
return ;
90
86
}
91
87
92
- unsafe {
93
- fixed ( byte * inbuf = input ) {
94
- complete = StepMboxMarkerStart ( inbuf , ref midline ) ;
95
- }
96
- }
88
+ complete = StepMboxMarkerStart ( ref midline ) ;
97
89
} while ( ! complete ) ;
98
90
99
91
var mboxMarkerOffset = GetOffset ( inputIndex ) ;
@@ -109,13 +101,8 @@ async Task StepMboxMarkerAsync (CancellationToken cancellationToken)
109
101
}
110
102
111
103
int startIndex = inputIndex ;
112
- int count ;
113
104
114
- unsafe {
115
- fixed ( byte * inbuf = input ) {
116
- complete = StepMboxMarker ( inbuf , out count ) ;
117
- }
118
- }
105
+ complete = StepMboxMarker ( out int count ) ;
119
106
120
107
// TODO: Remove beginOffset and lineNumber arguments from OnMboxMarkerReadAsync() in v5.0
121
108
await OnMboxMarkerReadAsync ( input , startIndex , count , mboxMarkerOffset , mboxMarkerLineNumber , cancellationToken ) . ConfigureAwait ( false ) ;
@@ -177,41 +164,27 @@ async Task StepHeadersAsync (CancellationToken cancellationToken)
177
164
}
178
165
179
166
// Scan ahead a bit to see if this looks like an invalid header.
180
- do {
181
- unsafe {
182
- fixed ( byte * inbuf = input ) {
183
- if ( TryDetectInvalidHeader ( inbuf , out invalid , out fieldNameLength , out headerFieldLength ) )
184
- break ;
185
- }
186
- }
187
-
167
+ while ( ! TryDetectInvalidHeader ( out invalid , out fieldNameLength , out headerFieldLength ) ) {
188
168
int atleast = ( inputEnd - inputIndex ) + 1 ;
189
169
190
170
if ( await ReadAheadAsync ( atleast , 0 , cancellationToken ) . ConfigureAwait ( false ) < atleast ) {
191
171
// Not enough input to even find the ':'... mark as invalid and continue?
192
172
invalid = true ;
193
173
break ;
194
174
}
195
- } while ( true ) ;
175
+ }
196
176
197
177
if ( invalid ) {
198
178
// Figure out why this is an invalid header.
199
179
200
180
if ( input [ inputIndex ] == ( byte ) '-' ) {
201
181
// Check for a boundary marker. If the message is properly formatted, this will NEVER happen.
202
- do {
203
- unsafe {
204
- fixed ( byte * inbuf = input ) {
205
- if ( TryCheckBoundaryWithinHeaderBlock ( inbuf ) )
206
- break ;
207
- }
208
- }
209
-
182
+ while ( ! TryCheckBoundaryWithinHeaderBlock ( ) ) {
210
183
int atleast = ( inputEnd - inputIndex ) + 1 ;
211
184
212
185
if ( await ReadAheadAsync ( atleast , 0 , cancellationToken ) . ConfigureAwait ( false ) < atleast )
213
186
break ;
214
- } while ( true ) ;
187
+ }
215
188
216
189
// Note: If a boundary was discovered, then the state will be updated to MimeParserState.Boundary.
217
190
if ( state == MimeParserState . Boundary )
@@ -220,19 +193,12 @@ async Task StepHeadersAsync (CancellationToken cancellationToken)
220
193
// Fall through and act as if we're consuming a header.
221
194
} else if ( input [ inputIndex ] == ( byte ) 'F' || input [ inputIndex ] == ( byte ) '>' ) {
222
195
// Check for an mbox-style From-line. Again, if the message is properly formatted and not truncated, this will NEVER happen.
223
- do {
224
- unsafe {
225
- fixed ( byte * inbuf = input ) {
226
- if ( TryCheckMboxMarkerWithinHeaderBlock ( inbuf ) )
227
- break ;
228
- }
229
- }
230
-
196
+ while ( ! TryCheckMboxMarkerWithinHeaderBlock ( ) ) {
231
197
int atleast = ( inputEnd - inputIndex ) + 1 ;
232
198
233
199
if ( await ReadAheadAsync ( atleast , 0 , cancellationToken ) . ConfigureAwait ( false ) < atleast )
234
200
break ;
235
- } while ( true ) ;
201
+ }
236
202
237
203
// state will be one of the following values:
238
204
// 1. Complete: This means that we've found an actual mbox marker
@@ -260,20 +226,13 @@ async Task StepHeadersAsync (CancellationToken cancellationToken)
260
226
bool midline = true ;
261
227
262
228
// Consume the header value.
263
- do {
264
- unsafe {
265
- fixed ( byte * inbuf = input ) {
266
- if ( StepHeaderValue ( inbuf , ref midline ) )
267
- break ;
268
- }
269
- }
270
-
229
+ while ( ! StepHeaderValue ( ref midline ) ) {
271
230
if ( await ReadAheadAsync ( 1 , 0 , cancellationToken ) . ConfigureAwait ( false ) == 0 ) {
272
231
state = MimeParserState . Content ;
273
232
eof = true ;
274
233
break ;
275
234
}
276
- } while ( true ) ;
235
+ }
277
236
278
237
if ( toplevel && headerCount == 0 && invalid && ! IsMboxMarker ( headerBuffer ) ) {
279
238
state = MimeParserState . Error ;
@@ -293,12 +252,8 @@ async Task StepHeadersAsync (CancellationToken cancellationToken)
293
252
async Task < bool > SkipLineAsync ( bool consumeNewLine , CancellationToken cancellationToken )
294
253
{
295
254
do {
296
- unsafe {
297
- fixed ( byte * inbuf = input ) {
298
- if ( InnerSkipLine ( inbuf , consumeNewLine ) )
299
- return true ;
300
- }
301
- }
255
+ if ( InnerSkipLine ( consumeNewLine ) )
256
+ return true ;
302
257
303
258
if ( await ReadAheadAsync ( ReadAheadSize , 1 , cancellationToken ) . ConfigureAwait ( false ) <= 0 )
304
259
return false ;
@@ -346,11 +301,7 @@ async Task<ScanContentResult> ScanContentAsync (ScanContentType type, long begin
346
301
347
302
int contentIndex = inputIndex ;
348
303
349
- unsafe {
350
- fixed ( byte * inbuf = input ) {
351
- ScanContent ( inbuf , ref nleft , ref midline , ref formats ) ;
352
- }
353
- }
304
+ ScanContent ( ref nleft , ref midline , ref formats ) ;
354
305
355
306
if ( contentIndex < inputIndex ) {
356
307
switch ( type ) {
@@ -413,24 +364,11 @@ async Task<int> ConstructMessagePartAsync (int depth, CancellationToken cancella
413
364
return 0 ;
414
365
}
415
366
416
- unsafe {
417
- fixed ( byte * inbuf = input ) {
418
- byte * start = inbuf + inputIndex ;
419
- byte * inend = inbuf + inputEnd ;
420
- byte * inptr = start ;
421
-
422
- * inend = ( byte ) '\n ' ;
423
-
424
- while ( * inptr != ( byte ) '\n ' )
425
- inptr ++ ;
426
-
427
- // Note: This isn't obvious, but if the "boundary" that was found is an Mbox "From " line, then
428
- // either the current stream offset is >= contentEnd -or- RespectContentLength is false. It will
429
- // *never* be an Mbox "From " marker in Entity mode.
430
- if ( ( boundary = CheckBoundary ( inputIndex , start , ( int ) ( inptr - start ) ) ) != BoundaryType . None )
431
- return GetLineCount ( beginLineNumber , beginOffset , GetEndOffset ( inputIndex ) ) ;
432
- }
433
- }
367
+ // Note: This isn't obvious, but if the "boundary" that was found is an Mbox "From " line, then
368
+ // either the current stream offset is >= contentEnd -or- RespectContentLength is false. It will
369
+ // *never* be an Mbox "From " marker in Entity mode.
370
+ if ( ( boundary = CheckBoundary ( ) ) != BoundaryType . None )
371
+ return GetLineCount ( beginLineNumber , beginOffset , GetEndOffset ( inputIndex ) ) ;
434
372
}
435
373
436
374
// Note: When parsing non-toplevel parts, the header parser will never result in the Error state.
@@ -626,14 +564,10 @@ async Task<int> ConstructMultipartAsync (ContentType contentType, int depth, Can
626
564
// We either found the end of the stream or we found a parent's boundary
627
565
PopBoundary ( ) ;
628
566
629
- unsafe {
630
- fixed ( byte * inbuf = input ) {
631
- if ( boundary == BoundaryType . ParentEndBoundary && FoundImmediateBoundary ( inbuf , true ) )
632
- boundary = BoundaryType . ImmediateEndBoundary ;
633
- else if ( boundary == BoundaryType . ParentBoundary && FoundImmediateBoundary ( inbuf , false ) )
634
- boundary = BoundaryType . ImmediateBoundary ;
635
- }
636
- }
567
+ if ( boundary == BoundaryType . ParentEndBoundary && FoundImmediateBoundary ( true ) )
568
+ boundary = BoundaryType . ImmediateEndBoundary ;
569
+ else if ( boundary == BoundaryType . ParentBoundary && FoundImmediateBoundary ( false ) )
570
+ boundary = BoundaryType . ImmediateBoundary ;
637
571
638
572
endOffset = GetEndOffset ( inputIndex ) ;
639
573
0 commit comments