Fix miscellaneous nullability warnings

This commit is contained in:
Matt Nadareski
2023-09-13 00:29:21 -04:00
parent 24c542c22f
commit d7d81665a0
4 changed files with 42 additions and 4 deletions

View File

@@ -308,7 +308,11 @@ namespace BinaryObjectScanner.Wrappers
#endif
{
// If we have an invalid sector
#if NET48
if (startingSector < 0 || FATSectorNumbers == null || (long)startingSector >= FATSectorNumbers.Length)
#else
if (startingSector == null || startingSector < 0 || FATSectorNumbers == null || (long)startingSector >= FATSectorNumbers.Length)
#endif
return null;
// Setup the returned list
@@ -321,8 +325,17 @@ namespace BinaryObjectScanner.Wrappers
var lastSector = startingSector;
while (true)
{
#if NET6_0_OR_GREATER
if (lastSector == null)
break;
#endif
// Get the next sector from the lookup table
#if NET48
var nextSector = FATSectorNumbers[(uint)lastSector];
#else
var nextSector = FATSectorNumbers[(uint)lastSector!.Value];
#endif
// If we have an end of chain or free sector
if (nextSector == SabreTools.Models.CFB.SectorNumber.ENDOFCHAIN || nextSector == SabreTools.Models.CFB.SectorNumber.FREESECT)
@@ -412,7 +425,11 @@ namespace BinaryObjectScanner.Wrappers
#endif
{
// If we have an invalid sector
#if NET48
if (startingSector < 0 || MiniFATSectorNumbers == null || (long)startingSector >= MiniFATSectorNumbers.Length)
#else
if (startingSector == null || startingSector < 0 || MiniFATSectorNumbers == null || (long)startingSector >= MiniFATSectorNumbers.Length)
#endif
return null;
// Setup the returned list
@@ -425,8 +442,17 @@ namespace BinaryObjectScanner.Wrappers
var lastSector = startingSector;
while (true)
{
#if NET6_0_OR_GREATER
if (lastSector == null)
break;
#endif
// Get the next sector from the lookup table
#if NET48
var nextSector = MiniFATSectorNumbers[(uint)lastSector];
#else
var nextSector = MiniFATSectorNumbers[(uint)lastSector!.Value];
#endif
// If we have an end of chain or free sector
if (nextSector == SabreTools.Models.CFB.SectorNumber.ENDOFCHAIN || nextSector == SabreTools.Models.CFB.SectorNumber.FREESECT)

View File

@@ -1087,6 +1087,11 @@ namespace BinaryObjectScanner.Wrappers
if (_stubExecutableData != null)
return _stubExecutableData;
#if NET6_0_OR_GREATER
if (Stub_NewExeHeaderAddr == null)
return null;
#endif
// Populate the raw stub executable data based on the source
int endOfStubHeader = 0x40;
int lengthOfStubExecutableData = (int)Stub_NewExeHeaderAddr - endOfStubHeader;
@@ -1133,7 +1138,7 @@ namespace BinaryObjectScanner.Wrappers
#if NET48
public Dictionary<string, object> ResourceData
#else
public Dictionary<string, object>? ResourceData
public Dictionary<string, object?>? ResourceData
#endif
{
get
@@ -4403,7 +4408,10 @@ namespace BinaryObjectScanner.Wrappers
return -1;
// Otherwise, find the section it exists within
return OH_AddressOfEntryPoint.Value.ContainingSectionIndex(SectionTable);
return OH_AddressOfEntryPoint.Value.ContainingSectionIndex(SectionTable
.Where(sh => sh != null)
.Cast<SabreTools.Models.PortableExecutable.SectionHeader>()
.ToArray());
#endif
}

View File

@@ -852,7 +852,7 @@ namespace BinaryObjectScanner.Wrappers
// Reverse and assemble the filename
parentNames.Reverse();
filename = Path.Combine(parentNames.ToArray());
filename = Path.Combine(parentNames.Cast<string>().ToArray());
// Get the file offset
long fileOffset;
@@ -866,7 +866,7 @@ namespace BinaryObjectScanner.Wrappers
}
// Adjust the file offset
fileOffset += FileDataOffset.Value;
fileOffset += FileDataOffset ?? 0;
// Get the file sizes
long fileSize, outputFileSize;

View File

@@ -152,7 +152,11 @@ namespace BinaryObjectScanner.Wrappers
/// <summary>
/// Array of archive filenames attached to the given VPK
/// </summary>
#if NET48
private string[] _archiveFilenames = null;
#else
private string[]? _archiveFilenames = null;
#endif
#endregion