Fix possible null assignment to non-nullable entities.

This commit is contained in:
2023-10-04 09:55:17 +01:00
parent 2a6e052a62
commit bc8bf7a2dc
27 changed files with 55 additions and 36 deletions

View File

@@ -190,9 +190,15 @@ public sealed class MainWindowViewModel : ViewModelBase
set => this.RaiseAndSetIfChanged(ref _devicesSupported, value); set => this.RaiseAndSetIfChanged(ref _devicesSupported, value);
} }
public bool NativeMenuSupported => public bool NativeMenuSupported
NativeMenu.GetIsNativeMenuExported((Application.Current?.ApplicationLifetime as {
IClassicDesktopStyleApplicationLifetime)?.MainWindow); get
{
Window mainWindow = (Application.Current?.ApplicationLifetime as
IClassicDesktopStyleApplicationLifetime)?.MainWindow;
return mainWindow is not null && NativeMenu.GetIsNativeMenuExported(mainWindow);
}
}
[NotNull] [NotNull]
public string Greeting => UI.Welcome_to_Aaru; public string Greeting => UI.Welcome_to_Aaru;

View File

@@ -571,6 +571,11 @@ public sealed partial class Udif
} }
buffer = new byte[SECTOR_SIZE]; buffer = new byte[SECTOR_SIZE];
// Shall not happen
if(data is null)
return ErrorNumber.InvalidArgument;
Array.Copy(data, relOff, buffer, 0, SECTOR_SIZE); Array.Copy(data, relOff, buffer, 0, SECTOR_SIZE);
if(_sectorCache.Count >= MAX_CACHED_SECTORS) if(_sectorCache.Count >= MAX_CACHED_SECTORS)

View File

@@ -31,6 +31,7 @@
// Copyright © 2011-2023 Natalia Portillo // Copyright © 2011-2023 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
using System;
using System.CommandLine; using System.CommandLine;
using System.CommandLine.NamingConventionBinder; using System.CommandLine.NamingConventionBinder;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
@@ -54,7 +55,7 @@ sealed class ArchiveInfoCommand : Command
Name = "archive-path" Name = "archive-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string imagePath) public static int Invoke(bool debug, bool verbose, string imagePath)

View File

@@ -30,6 +30,7 @@
// Copyright © 2011-2023 Natalia Portillo // Copyright © 2011-2023 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
using System;
using System.CommandLine.NamingConventionBinder; using System.CommandLine.NamingConventionBinder;
using System.Linq; using System.Linq;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
@@ -45,7 +46,7 @@ namespace Aaru.Commands.Database;
sealed class StatisticsCommand : Command sealed class StatisticsCommand : Command
{ {
public StatisticsCommand() : base("stats", UI.Database_Stats_Command_Description) => public StatisticsCommand() : base("stats", UI.Database_Stats_Command_Description) =>
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
public static int Invoke(bool debug, bool verbose) public static int Invoke(bool debug, bool verbose)
{ {

View File

@@ -72,7 +72,7 @@ sealed class DeviceReportCommand : Command
Add(new Option<bool>(new[] { "--trap-disc", "-t" }, () => false, UI.Device_report_using_trap_disc)); Add(new Option<bool>(new[] { "--trap-disc", "-t" }, () => false, UI.Device_report_using_trap_disc));
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string devicePath, bool trapDisc) public static int Invoke(bool debug, bool verbose, string devicePath, bool trapDisc)
@@ -274,7 +274,7 @@ sealed class DeviceReportCommand : Command
} }
else if(!removable && else if(!removable &&
report.ATA.IdentifyDevice?.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit. report.ATA.IdentifyDevice?.GeneralConfiguration.HasFlag(Identify.GeneralConfigurationBit.
Removable) == true) Removable) == true)
removable = AnsiConsole.Confirm($"[italic]{UI.Is_the_media_removable}[/]"); removable = AnsiConsole.Confirm($"[italic]{UI.Is_the_media_removable}[/]");
if(removable) if(removable)

View File

@@ -77,7 +77,7 @@ sealed class DeviceInfoCommand : Command
Name = "device-path" Name = "device-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string devicePath, string outputPrefix) public static int Invoke(bool debug, bool verbose, string devicePath, string outputPrefix)

View File

@@ -30,6 +30,7 @@
// Copyright © 2011-2023 Natalia Portillo // Copyright © 2011-2023 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
using System;
using System.CommandLine; using System.CommandLine;
using System.CommandLine.NamingConventionBinder; using System.CommandLine.NamingConventionBinder;
using System.Linq; using System.Linq;
@@ -56,7 +57,7 @@ sealed class ListDevicesCommand : Command
Name = "aaru-remote-host" Name = "aaru-remote-host"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, [CanBeNull] string aaruRemoteHost) public static int Invoke(bool debug, bool verbose, [CanBeNull] string aaruRemoteHost)

View File

@@ -80,7 +80,7 @@ sealed class ExtractFilesCommand : Command
Name = "output-dir" Name = "output-dir"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string encoding, bool xattrs, string imagePath, public static int Invoke(bool debug, bool verbose, string encoding, bool xattrs, string imagePath,

View File

@@ -72,7 +72,7 @@ sealed class LsCommand : Command
Name = "image-path" Name = "image-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string encoding, string imagePath, bool longFormat, public static int Invoke(bool debug, bool verbose, string encoding, string imagePath, bool longFormat,

View File

@@ -50,7 +50,7 @@ sealed class ListOptionsCommand : Command
const string MODULE_NAME = "List-Options command"; const string MODULE_NAME = "List-Options command";
public ListOptionsCommand() : base("options", UI.Filesystem_Options_Command_Description) => public ListOptionsCommand() : base("options", UI.Filesystem_Options_Command_Description) =>
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
public static int Invoke(bool debug, bool verbose) public static int Invoke(bool debug, bool verbose)
{ {

View File

@@ -50,7 +50,7 @@ sealed class FormatsCommand : Command
const string MODULE_NAME = "Formats command"; const string MODULE_NAME = "Formats command";
public FormatsCommand() : base("formats", UI.List_Formats_Command_Description) => public FormatsCommand() : base("formats", UI.List_Formats_Command_Description) =>
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
public static int Invoke(bool verbose, bool debug) public static int Invoke(bool verbose, bool debug)
{ {

View File

@@ -89,7 +89,7 @@ sealed class ChecksumCommand : Command
Name = "image-path" Name = "image-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, bool adler32, bool crc16, bool crc32, bool crc64, public static int Invoke(bool debug, bool verbose, bool adler32, bool crc16, bool crc32, bool crc64,

View File

@@ -71,7 +71,7 @@ sealed class CompareCommand : Command
Name = "image-path2" Name = "image-path2"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string imagePath1, string imagePath2) public static int Invoke(bool debug, bool verbose, string imagePath1, string imagePath2)

View File

@@ -138,7 +138,7 @@ sealed class ConvertImageCommand : Command
Name = "output-path" Name = "output-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool verbose, bool debug, string cicmXml, string comments, int count, string creator, public static int Invoke(bool verbose, bool debug, string cicmXml, string comments, int count, string creator,
@@ -564,7 +564,7 @@ sealed class ConvertImageCommand : Command
} }
foreach(MediaTagType mediaTag in inputFormat.Info.ReadableMediaTags.Where(mediaTag => foreach(MediaTagType mediaTag in inputFormat.Info.ReadableMediaTags.Where(mediaTag =>
!outputFormat.SupportedMediaTags.Contains(mediaTag) && !force)) !outputFormat.SupportedMediaTags.Contains(mediaTag) && !force))
{ {
AaruConsole.ErrorWriteLine(UI.Converting_image_will_lose_media_tag_0, mediaTag); AaruConsole.ErrorWriteLine(UI.Converting_image_will_lose_media_tag_0, mediaTag);
AaruConsole.ErrorWriteLine(UI.If_you_dont_care_use_force_option); AaruConsole.ErrorWriteLine(UI.If_you_dont_care_use_force_option);
@@ -575,7 +575,7 @@ sealed class ConvertImageCommand : Command
bool useLong = inputFormat.Info.ReadableSectorTags.Count != 0; bool useLong = inputFormat.Info.ReadableSectorTags.Count != 0;
foreach(SectorTagType sectorTag in inputFormat.Info.ReadableSectorTags.Where(sectorTag => foreach(SectorTagType sectorTag in inputFormat.Info.ReadableSectorTags.Where(sectorTag =>
!outputFormat.SupportedSectorTags.Contains(sectorTag))) !outputFormat.SupportedSectorTags.Contains(sectorTag)))
{ {
if(force) if(force)
{ {
@@ -624,7 +624,7 @@ sealed class ConvertImageCommand : Command
} }
if((outputFormat as IWritableOpticalImage)?.OpticalCapabilities.HasFlag(OpticalImageCapabilities. if((outputFormat as IWritableOpticalImage)?.OpticalCapabilities.HasFlag(OpticalImageCapabilities.
CanStoreSessions) != true && CanStoreSessions) != true &&
(inputFormat as IOpticalMediaImage)?.Sessions?.Count > 1) (inputFormat as IOpticalMediaImage)?.Sessions?.Count > 1)
{ {
// TODO: Disabled until 6.0 // TODO: Disabled until 6.0
@@ -639,7 +639,7 @@ sealed class ConvertImageCommand : Command
} }
if((outputFormat as IWritableOpticalImage)?.OpticalCapabilities.HasFlag(OpticalImageCapabilities. if((outputFormat as IWritableOpticalImage)?.OpticalCapabilities.HasFlag(OpticalImageCapabilities.
CanStoreHiddenTracks) != true && CanStoreHiddenTracks) != true &&
(inputFormat as IOpticalMediaImage)?.Tracks?.Any(t => t.Sequence == 0) == true) (inputFormat as IOpticalMediaImage)?.Tracks?.Any(t => t.Sequence == 0) == true)
{ {
// TODO: Disabled until 6.0 // TODO: Disabled until 6.0
@@ -707,7 +707,7 @@ sealed class ConvertImageCommand : Command
List<DumpHardware> dumpHardware = inputFormat.DumpHardware; List<DumpHardware> dumpHardware = inputFormat.DumpHardware;
foreach(MediaTagType mediaTag in inputFormat.Info.ReadableMediaTags.Where(mediaTag => foreach(MediaTagType mediaTag in inputFormat.Info.ReadableMediaTags.Where(mediaTag =>
!force || outputFormat.SupportedMediaTags.Contains(mediaTag))) !force || outputFormat.SupportedMediaTags.Contains(mediaTag)))
{ {
ErrorNumber errorNumber = ErrorNumber.NoError; ErrorNumber errorNumber = ErrorNumber.NoError;
@@ -908,7 +908,7 @@ sealed class ConvertImageCommand : Command
Core.Filesystems. Core.Filesystems.
Identify(inputOptical, Identify(inputOptical,
out List<string> out List<string>
idPlugins, p); idPlugins, p);
return idPlugins. return idPlugins.
Contains("iso9660 filesystem"); Contains("iso9660 filesystem");
@@ -969,7 +969,7 @@ sealed class ConvertImageCommand : Command
Core.Filesystems. Core.Filesystems.
Identify(inputOptical, Identify(inputOptical,
out List<string> out List<string>
idPlugins, p); idPlugins, p);
return idPlugins. return idPlugins.
Contains("iso9660 filesystem"); Contains("iso9660 filesystem");

View File

@@ -72,7 +72,7 @@ sealed class CreateSidecarCommand : Command
Name = "image-path" Name = "image-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, uint blockSize, [CanBeNull] string encodingName, public static int Invoke(bool debug, bool verbose, uint blockSize, [CanBeNull] string encodingName,

View File

@@ -30,6 +30,7 @@
// Copyright © 2011-2023 Natalia Portillo // Copyright © 2011-2023 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
using System;
using System.CommandLine; using System.CommandLine;
using System.CommandLine.NamingConventionBinder; using System.CommandLine.NamingConventionBinder;
using System.Globalization; using System.Globalization;
@@ -68,7 +69,7 @@ sealed class DecodeCommand : Command
Name = "image-path" Name = "image-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool verbose, bool debug, bool diskTags, string imagePath, string length, bool sectorTags, public static int Invoke(bool verbose, bool debug, bool diskTags, string imagePath, string length, bool sectorTags,

View File

@@ -30,6 +30,7 @@
// Copyright © 2011-2023 Natalia Portillo // Copyright © 2011-2023 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
using System;
using System.CommandLine; using System.CommandLine;
using System.CommandLine.NamingConventionBinder; using System.CommandLine.NamingConventionBinder;
using Aaru.CommonTypes; using Aaru.CommonTypes;
@@ -65,7 +66,7 @@ sealed class EntropyCommand : Command
Name = "image-path" Name = "image-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, bool duplicatedSectors, string imagePath, bool separatedTracks, public static int Invoke(bool debug, bool verbose, bool duplicatedSectors, string imagePath, bool separatedTracks,

View File

@@ -56,7 +56,7 @@ sealed class ImageInfoCommand : Command
Name = "image-path" Name = "image-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string imagePath) public static int Invoke(bool debug, bool verbose, string imagePath)

View File

@@ -50,7 +50,7 @@ sealed class ListOptionsCommand : Command
const string MODULE_NAME = "List-Options command"; const string MODULE_NAME = "List-Options command";
public ListOptionsCommand() : base("options", UI.Image_Options_Command_Description) => public ListOptionsCommand() : base("options", UI.Image_Options_Command_Description) =>
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
public static int Invoke(bool debug, bool verbose) public static int Invoke(bool debug, bool verbose)
{ {

View File

@@ -65,7 +65,7 @@ sealed class PrintHexCommand : Command
Name = "image-path" Name = "image-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string imagePath, ulong length, bool longSectors, ulong start, public static int Invoke(bool debug, bool verbose, string imagePath, ulong length, bool longSectors, ulong start,

View File

@@ -30,6 +30,7 @@
// Copyright © 2011-2023 Natalia Portillo // Copyright © 2011-2023 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.CommandLine; using System.CommandLine;
using System.CommandLine.NamingConventionBinder; using System.CommandLine.NamingConventionBinder;
@@ -70,7 +71,7 @@ sealed class VerifyCommand : Command
Name = "image-path" Name = "image-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string imagePath, bool verifyDisc, bool verifySectors, public static int Invoke(bool debug, bool verbose, string imagePath, bool verifyDisc, bool verifySectors,

View File

@@ -30,6 +30,7 @@
// Copyright © 2011-2023 Natalia Portillo // Copyright © 2011-2023 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
using System;
using System.CommandLine; using System.CommandLine;
using System.CommandLine.NamingConventionBinder; using System.CommandLine.NamingConventionBinder;
using System.Linq; using System.Linq;
@@ -47,7 +48,7 @@ sealed class ListEncodingsCommand : Command
const string MODULE_NAME = "List-Encodings command"; const string MODULE_NAME = "List-Encodings command";
public ListEncodingsCommand() : base("list-encodings", UI.List_Encodings_Command_Description) => public ListEncodingsCommand() : base("list-encodings", UI.List_Encodings_Command_Description) =>
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
public static int Invoke(bool debug, bool verbose) public static int Invoke(bool debug, bool verbose)
{ {

View File

@@ -49,7 +49,7 @@ sealed class ListNamespacesCommand : Command
const string MODULE_NAME = "List-Namespaces command"; const string MODULE_NAME = "List-Namespaces command";
public ListNamespacesCommand() : base("list-namespaces", UI.List_Namespaces_Command_Description) => public ListNamespacesCommand() : base("list-namespaces", UI.List_Namespaces_Command_Description) =>
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
public static int Invoke(bool debug, bool verbose) public static int Invoke(bool debug, bool verbose)
{ {

View File

@@ -156,7 +156,7 @@ sealed class DumpMediaCommand : Command
Add(new Option<string>(new[] { "--aaru-metadata", "-m" }, () => null, Add(new Option<string>(new[] { "--aaru-metadata", "-m" }, () => null,
"Take metadata from existing Aaru Metadata sidecar.")); "Take metadata from existing Aaru Metadata sidecar."));
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string cicmXml, string devicePath, bool resume, string encoding, public static int Invoke(bool debug, bool verbose, string cicmXml, string devicePath, bool resume, string encoding,

View File

@@ -78,7 +78,7 @@ sealed class MediaInfoCommand : Command
Name = "device-path" Name = "device-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string devicePath, string outputPrefix) public static int Invoke(bool debug, bool verbose, string devicePath, string outputPrefix)

View File

@@ -30,6 +30,7 @@
// Copyright © 2011-2023 Natalia Portillo // Copyright © 2011-2023 Natalia Portillo
// ****************************************************************************/ // ****************************************************************************/
using System;
using System.CommandLine; using System.CommandLine;
using System.CommandLine.NamingConventionBinder; using System.CommandLine.NamingConventionBinder;
using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Enums;
@@ -66,7 +67,7 @@ sealed class MediaScanCommand : Command
Name = "device-path" Name = "device-path"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string devicePath, string ibgLog, string mhddLog, public static int Invoke(bool debug, bool verbose, string devicePath, string ibgLog, string mhddLog,

View File

@@ -57,7 +57,7 @@ sealed class RemoteCommand : Command
Name = "host" Name = "host"
}); });
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke))); Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)) ?? throw new NullReferenceException());
} }
public static int Invoke(bool debug, bool verbose, string host) public static int Invoke(bool debug, bool verbose, string host)