From 24c542c22fd48bde0af7d0c2e8dcf234c87d01bd Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 13 Sep 2023 00:16:27 -0400 Subject: [PATCH] Fix "converting null literal" warnings --- BinaryObjectScanner.Wrappers/BSP.cs | 8 ++++++ .../MicrosoftCabinet.cs | 6 +++- BinaryObjectScanner.Wrappers/PAK.cs | 2 +- .../PortableExecutable.cs | 28 ++++++++++++++++--- BinaryObjectScanner.Wrappers/Quantum.cs | 6 +++- BinaryObjectScanner.Wrappers/WrapperBase.cs | 4 +++ 6 files changed, 47 insertions(+), 7 deletions(-) diff --git a/BinaryObjectScanner.Wrappers/BSP.cs b/BinaryObjectScanner.Wrappers/BSP.cs index 7245928f..389eb105 100644 --- a/BinaryObjectScanner.Wrappers/BSP.cs +++ b/BinaryObjectScanner.Wrappers/BSP.cs @@ -350,7 +350,11 @@ namespace BinaryObjectScanner.Wrappers return false; // Read the data +#if NET48 byte[] data = ReadFromDataSource((int)lump.Offset, (int)lump.Length); +#else + byte[]? data = ReadFromDataSource((int)lump.Offset, (int)lump.Length); +#endif if (data == null) return false; @@ -442,7 +446,11 @@ namespace BinaryObjectScanner.Wrappers return false; // Read the data +#if NET48 byte[] data = CreateTextureData(texture); +#else + byte[]? data = CreateTextureData(texture); +#endif if (data == null) return false; diff --git a/BinaryObjectScanner.Wrappers/MicrosoftCabinet.cs b/BinaryObjectScanner.Wrappers/MicrosoftCabinet.cs index 609b104f..fb4230fe 100644 --- a/BinaryObjectScanner.Wrappers/MicrosoftCabinet.cs +++ b/BinaryObjectScanner.Wrappers/MicrosoftCabinet.cs @@ -351,7 +351,11 @@ namespace BinaryObjectScanner.Wrappers if (dataBlock == null) continue; +#if NET48 byte[] decompressed = new byte[dataBlock.UncompressedSize]; +#else + byte[]? decompressed = new byte[dataBlock.UncompressedSize]; +#endif switch (folder.CompressionType & SabreTools.Models.MicrosoftCabinet.CompressionType.MASK_TYPE) { case SabreTools.Models.MicrosoftCabinet.CompressionType.TYPE_NONE: @@ -649,7 +653,7 @@ namespace BinaryObjectScanner.Wrappers { for (int j = 0; j < entry.DataBlocks.Length; j++) { - SabreTools.Models.MicrosoftCabinet.CFDATA dataBlock = entry.DataBlocks[j]; + var dataBlock = entry.DataBlocks[j]; builder.AppendLine($" Data Block {j}"); if (dataBlock == null) { diff --git a/BinaryObjectScanner.Wrappers/PAK.cs b/BinaryObjectScanner.Wrappers/PAK.cs index d0cf45d1..23e6f833 100644 --- a/BinaryObjectScanner.Wrappers/PAK.cs +++ b/BinaryObjectScanner.Wrappers/PAK.cs @@ -258,7 +258,7 @@ namespace BinaryObjectScanner.Wrappers #if NET48 byte[] data = ReadFromDataSource((int)directoryItem.ItemOffset, (int)directoryItem.ItemLength); #else - byte[] data = ReadFromDataSource((int)directoryItem.ItemOffset, (int)directoryItem.ItemLength); + byte[]? data = ReadFromDataSource((int)directoryItem.ItemOffset, (int)directoryItem.ItemLength); #endif if (data == null) return false; diff --git a/BinaryObjectScanner.Wrappers/PortableExecutable.cs b/BinaryObjectScanner.Wrappers/PortableExecutable.cs index 926c640c..74001f3b 100644 --- a/BinaryObjectScanner.Wrappers/PortableExecutable.cs +++ b/BinaryObjectScanner.Wrappers/PortableExecutable.cs @@ -3133,7 +3133,11 @@ namespace BinaryObjectScanner.Wrappers foreach (var kvp in stringTable) { int index = kvp.Key; +#if NET48 string stringValue = kvp.Value; +#else + string? stringValue = kvp.Value; +#endif builder.AppendLine($"{padding}String entry {index}: {stringValue}"); } } @@ -3206,13 +3210,21 @@ namespace BinaryObjectScanner.Wrappers else { int offset = 0; +#if NET48 byte[] magic = entry.Data.ReadBytes(ref offset, Math.Min(entry.Data.Length, 16)); +#else + byte[]? magic = entry.Data.ReadBytes(ref offset, Math.Min(entry.Data.Length, 16)); +#endif - if (entry.Data[0] == 0x4D && entry.Data[1] == 0x5A) + if (magic == null) + { + // No-op + } + else if (magic[0] == 0x4D && magic[1] == 0x5A) { builder.AppendLine($"{padding}Data: [Embedded Executable File]"); // TODO: Parse this out and print separately } - else if (entry.Data[0] == 0x4D && entry.Data[1] == 0x53 && entry.Data[2] == 0x46 && entry.Data[3] == 0x54) + else if (magic[0] == 0x4D && magic[1] == 0x53 && magic[2] == 0x46 && magic[3] == 0x54) { builder.AppendLine($"{padding}Data: [Embedded OLE Library File]"); // TODO: Parse this out and print separately } @@ -3773,13 +3785,21 @@ namespace BinaryObjectScanner.Wrappers else { int offset = 0; +#if NET48 byte[] magic = entry.Data.ReadBytes(ref offset, Math.Min(entry.Data.Length, 16)); +#else + byte[]? magic = entry.Data.ReadBytes(ref offset, Math.Min(entry.Data.Length, 16)); +#endif - if (entry.Data[0] == 0x4D && entry.Data[1] == 0x5A) + if (magic == null) + { + // No-op + } + else if (magic[0] == 0x4D && magic[1] == 0x5A) { builder.AppendLine($"{padding}Data: [Embedded Executable File]"); // TODO: Parse this out and print separately } - else if (entry.Data[0] == 0x4D && entry.Data[1] == 0x53 && entry.Data[2] == 0x46 && entry.Data[3] == 0x54) + else if (magic[0] == 0x4D && magic[1] == 0x53 && magic[2] == 0x46 && magic[3] == 0x54) { builder.AppendLine($"{padding}Data: [Embedded OLE Library File]"); // TODO: Parse this out and print separately } diff --git a/BinaryObjectScanner.Wrappers/Quantum.cs b/BinaryObjectScanner.Wrappers/Quantum.cs index 75ee01d8..36820f47 100644 --- a/BinaryObjectScanner.Wrappers/Quantum.cs +++ b/BinaryObjectScanner.Wrappers/Quantum.cs @@ -201,7 +201,11 @@ namespace BinaryObjectScanner.Wrappers // Read the entire compressed data int compressedDataOffset = (int)CompressedDataOffset; int compressedDataLength = GetEndOfFile() - compressedDataOffset; +#if NET48 byte[] compressedData = ReadFromDataSource(compressedDataOffset, compressedDataLength); +#else + byte[]? compressedData = ReadFromDataSource(compressedDataOffset, compressedDataLength); +#endif // TODO: Figure out decompression // - Single-file archives seem to work @@ -324,7 +328,7 @@ namespace BinaryObjectScanner.Wrappers builder.AppendLine($" File Descriptor {i}"); if (fileDescriptor == null) { - builder.AppendLine(" [NULL]"); + builder.AppendLine(" [NULL]"); continue; } diff --git a/BinaryObjectScanner.Wrappers/WrapperBase.cs b/BinaryObjectScanner.Wrappers/WrapperBase.cs index 936f2167..50e7bf88 100644 --- a/BinaryObjectScanner.Wrappers/WrapperBase.cs +++ b/BinaryObjectScanner.Wrappers/WrapperBase.cs @@ -258,7 +258,11 @@ namespace BinaryObjectScanner.Wrappers #endif { // Read the data as a byte array first +#if NET48 byte[] sourceData = ReadFromDataSource(position, length); +#else + byte[]? sourceData = ReadFromDataSource(position, length); +#endif if (sourceData == null) return null;