Skip to content

Commit a8ea3e0

Browse files
committed
#2807 Add early return in InternalDetectFormat
1 parent 21ec18e commit a8ea3e0

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

src/ImageSharp/Image.Decode.cs

+4-7
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,18 @@ private static IImageFormat InternalDetectFormat(
128128
// Does the given stream contain enough data to fit in the header for the format
129129
// and does that data match the format specification?
130130
// Individual formats should still check since they are public.
131-
IImageFormat? format = null;
132131
foreach (IImageFormatDetector formatDetector in configuration.ImageFormatsManager.FormatDetectors)
133132
{
134133
if (formatDetector.HeaderSize <= headersBuffer.Length && formatDetector.TryDetectFormat(headersBuffer, out IImageFormat? attemptFormat))
135134
{
136-
format = attemptFormat;
135+
return attemptFormat;
137136
}
138137
}
139138

140-
if (format is null)
141-
{
142-
ImageFormatManager.ThrowInvalidDecoder(configuration.ImageFormatsManager);
143-
}
139+
ImageFormatManager.ThrowInvalidDecoder(configuration.ImageFormatsManager);
144140

145-
return format;
141+
// Need to write this otherwise compiler is not happy
142+
return null;
146143
}
147144

148145
/// <summary>

0 commit comments

Comments
 (0)